diff --git a/extras/tests/ResourceManager/allocVariant.cpp b/extras/tests/ResourceManager/allocVariant.cpp index d884a284..4a3685d8 100644 --- a/extras/tests/ResourceManager/allocVariant.cpp +++ b/extras/tests/ResourceManager/allocVariant.cpp @@ -2,9 +2,7 @@ // Copyright © 2014-2024, Benoit BLANCHON // MIT License -#include -#include -#include +#include #include #include "Allocators.hpp" diff --git a/src/ArduinoJson.hpp b/src/ArduinoJson.hpp index 51cd1ded..0149d87d 100644 --- a/src/ArduinoJson.hpp +++ b/src/ArduinoJson.hpp @@ -36,6 +36,7 @@ #include "ArduinoJson/Array/ElementProxy.hpp" #include "ArduinoJson/Array/Utilities.hpp" #include "ArduinoJson/Collection/CollectionImpl.hpp" +#include "ArduinoJson/Memory/ResourceManagerImpl.hpp" #include "ArduinoJson/Memory/VariantPoolImpl.hpp" #include "ArduinoJson/Object/MemberProxy.hpp" #include "ArduinoJson/Object/ObjectImpl.hpp" diff --git a/src/ArduinoJson/Collection/CollectionData.hpp b/src/ArduinoJson/Collection/CollectionData.hpp index 07fe7e04..f5706da0 100644 --- a/src/ArduinoJson/Collection/CollectionData.hpp +++ b/src/ArduinoJson/Collection/CollectionData.hpp @@ -116,7 +116,6 @@ class CollectionData { private: SlotWithId getPreviousSlot(VariantSlot*, const ResourceManager*) const; - void releaseSlot(SlotWithId, ResourceManager*); }; inline const VariantData* collectionToVariant( diff --git a/src/ArduinoJson/Collection/CollectionImpl.hpp b/src/ArduinoJson/Collection/CollectionImpl.hpp index 79d9ac72..d077627b 100644 --- a/src/ArduinoJson/Collection/CollectionImpl.hpp +++ b/src/ArduinoJson/Collection/CollectionImpl.hpp @@ -69,7 +69,7 @@ inline void CollectionData::clear(ResourceManager* resources) { auto currId = next; auto slot = resources->getSlot(next); next = slot->next(); - releaseSlot(SlotWithId(slot, currId), resources); + resources->freeSlot(SlotWithId(slot, currId)); } head_ = NULL_SLOT; @@ -102,7 +102,7 @@ inline void CollectionData::remove(iterator it, ResourceManager* resources) { head_ = next; if (next == NULL_SLOT) tail_ = prev.id(); - releaseSlot({it.slot_, it.currentId_}, resources); + resources->freeSlot({it.slot_, it.currentId_}); } inline size_t CollectionData::nesting(const ResourceManager* resources) const { @@ -122,12 +122,4 @@ inline size_t CollectionData::size(const ResourceManager* resources) const { 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 diff --git a/src/ArduinoJson/Memory/ResourceManager.hpp b/src/ArduinoJson/Memory/ResourceManager.hpp index 9a8cee84..2270e4f6 100644 --- a/src/ArduinoJson/Memory/ResourceManager.hpp +++ b/src/ArduinoJson/Memory/ResourceManager.hpp @@ -56,9 +56,7 @@ class ResourceManager { return p; } - void freeSlot(SlotWithId id) { - variantPools_.freeSlot(id); - } + void freeSlot(SlotWithId slot); VariantSlot* getSlot(SlotId id) const { return variantPools_.getSlot(id); diff --git a/src/ArduinoJson/Memory/ResourceManagerImpl.hpp b/src/ArduinoJson/Memory/ResourceManagerImpl.hpp new file mode 100644 index 00000000..136dc2dd --- /dev/null +++ b/src/ArduinoJson/Memory/ResourceManagerImpl.hpp @@ -0,0 +1,20 @@ +// ArduinoJson - https://arduinojson.org +// Copyright © 2014-2024, Benoit BLANCHON +// MIT License + +#pragma once + +#include +#include +#include + +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