Move CollectionData::releaseSlot() to ResourceManager::freeSlot()

This commit is contained in:
Benoit Blanchon
2024-05-17 16:32:39 +02:00
parent 0fe202af03
commit 60f9f7eff6
6 changed files with 25 additions and 17 deletions

View File

@ -2,9 +2,7 @@
// Copyright © 2014-2024, Benoit BLANCHON // Copyright © 2014-2024, Benoit BLANCHON
// MIT License // MIT License
#include <ArduinoJson/Memory/Alignment.hpp> #include <ArduinoJson.hpp>
#include <ArduinoJson/Memory/ResourceManager.hpp>
#include <ArduinoJson/Memory/VariantPoolImpl.hpp>
#include <catch.hpp> #include <catch.hpp>
#include "Allocators.hpp" #include "Allocators.hpp"

View File

@ -36,6 +36,7 @@
#include "ArduinoJson/Array/ElementProxy.hpp" #include "ArduinoJson/Array/ElementProxy.hpp"
#include "ArduinoJson/Array/Utilities.hpp" #include "ArduinoJson/Array/Utilities.hpp"
#include "ArduinoJson/Collection/CollectionImpl.hpp" #include "ArduinoJson/Collection/CollectionImpl.hpp"
#include "ArduinoJson/Memory/ResourceManagerImpl.hpp"
#include "ArduinoJson/Memory/VariantPoolImpl.hpp" #include "ArduinoJson/Memory/VariantPoolImpl.hpp"
#include "ArduinoJson/Object/MemberProxy.hpp" #include "ArduinoJson/Object/MemberProxy.hpp"
#include "ArduinoJson/Object/ObjectImpl.hpp" #include "ArduinoJson/Object/ObjectImpl.hpp"

View File

@ -116,7 +116,6 @@ class CollectionData {
private: private:
SlotWithId getPreviousSlot(VariantSlot*, const ResourceManager*) const; SlotWithId getPreviousSlot(VariantSlot*, const ResourceManager*) const;
void releaseSlot(SlotWithId, ResourceManager*);
}; };
inline const VariantData* collectionToVariant( inline const VariantData* collectionToVariant(

View File

@ -69,7 +69,7 @@ inline void CollectionData::clear(ResourceManager* resources) {
auto currId = next; auto currId = next;
auto slot = resources->getSlot(next); auto slot = resources->getSlot(next);
next = slot->next(); next = slot->next();
releaseSlot(SlotWithId(slot, currId), resources); resources->freeSlot(SlotWithId(slot, currId));
} }
head_ = NULL_SLOT; head_ = NULL_SLOT;
@ -102,7 +102,7 @@ inline void CollectionData::remove(iterator it, ResourceManager* resources) {
head_ = next; head_ = next;
if (next == NULL_SLOT) if (next == NULL_SLOT)
tail_ = prev.id(); tail_ = prev.id();
releaseSlot({it.slot_, it.currentId_}, resources); resources->freeSlot({it.slot_, it.currentId_});
} }
inline size_t CollectionData::nesting(const ResourceManager* resources) const { inline size_t CollectionData::nesting(const ResourceManager* resources) const {
@ -122,12 +122,4 @@ inline size_t CollectionData::size(const ResourceManager* resources) const {
return count; return count;
} }
inline void CollectionData::releaseSlot(SlotWithId slot,
ResourceManager* resources) {
if (slot->ownsKey())
resources->dereferenceString(slot->key());
slot->data()->setNull(resources);
resources->freeSlot(slot);
}
ARDUINOJSON_END_PRIVATE_NAMESPACE ARDUINOJSON_END_PRIVATE_NAMESPACE

View File

@ -56,9 +56,7 @@ class ResourceManager {
return p; return p;
} }
void freeSlot(SlotWithId id) { void freeSlot(SlotWithId slot);
variantPools_.freeSlot(id);
}
VariantSlot* getSlot(SlotId id) const { VariantSlot* getSlot(SlotId id) const {
return variantPools_.getSlot(id); return variantPools_.getSlot(id);

View File

@ -0,0 +1,20 @@
// ArduinoJson - https://arduinojson.org
// Copyright © 2014-2024, Benoit BLANCHON
// MIT License
#pragma once
#include <ArduinoJson/Collection/CollectionData.hpp>
#include <ArduinoJson/Memory/ResourceManager.hpp>
#include <ArduinoJson/Variant/VariantData.hpp>
ARDUINOJSON_BEGIN_PRIVATE_NAMESPACE
inline void ResourceManager::freeSlot(SlotWithId slot) {
if (slot->ownsKey())
dereferenceString(slot->key());
slot->data()->setNull(this);
variantPools_.freeSlot(slot);
}
ARDUINOJSON_END_PRIVATE_NAMESPACE