diff --git a/extras/tests/ResourceManager/clear.cpp b/extras/tests/ResourceManager/clear.cpp index e7707763..82592efa 100644 --- a/extras/tests/ResourceManager/clear.cpp +++ b/extras/tests/ResourceManager/clear.cpp @@ -3,7 +3,6 @@ // MIT License #include -#include #include #include diff --git a/extras/tests/ResourceManager/shrinkToFit.cpp b/extras/tests/ResourceManager/shrinkToFit.cpp index 4f1eb5de..c753dee6 100644 --- a/extras/tests/ResourceManager/shrinkToFit.cpp +++ b/extras/tests/ResourceManager/shrinkToFit.cpp @@ -3,7 +3,6 @@ // MIT License #include -#include #include #include "Allocators.hpp" diff --git a/extras/tests/ResourceManager/size.cpp b/extras/tests/ResourceManager/size.cpp index 17f3f42e..334060f3 100644 --- a/extras/tests/ResourceManager/size.cpp +++ b/extras/tests/ResourceManager/size.cpp @@ -3,7 +3,6 @@ // MIT License #include -#include #include #include "Allocators.hpp" diff --git a/extras/tests/ResourceManager/swap.cpp b/extras/tests/ResourceManager/swap.cpp index f5d8feec..8b8930f1 100644 --- a/extras/tests/ResourceManager/swap.cpp +++ b/extras/tests/ResourceManager/swap.cpp @@ -4,7 +4,6 @@ #include #include -#include #include #include "Allocators.hpp" diff --git a/src/ArduinoJson.hpp b/src/ArduinoJson.hpp index 8250664a..278828fa 100644 --- a/src/ArduinoJson.hpp +++ b/src/ArduinoJson.hpp @@ -45,7 +45,6 @@ #include "ArduinoJson/Array/ElementProxy.hpp" #include "ArduinoJson/Array/Utilities.hpp" #include "ArduinoJson/Collection/CollectionImpl.hpp" -#include "ArduinoJson/Memory/ResourceManagerImpl.hpp" #include "ArduinoJson/Object/MemberProxy.hpp" #include "ArduinoJson/Object/ObjectImpl.hpp" #include "ArduinoJson/Variant/ConverterImpl.hpp" diff --git a/src/ArduinoJson/Memory/ResourceManager.hpp b/src/ArduinoJson/Memory/ResourceManager.hpp index 52fbc352..d99f07f6 100644 --- a/src/ArduinoJson/Memory/ResourceManager.hpp +++ b/src/ArduinoJson/Memory/ResourceManager.hpp @@ -57,14 +57,42 @@ class ResourceManager { return overflowed_; } - Slot allocVariant(); - void freeVariant(Slot slot); - VariantData* getVariant(SlotId id) const; + Slot allocVariant() { + auto slot = variantPools_.allocSlot(allocator_); + if (!slot) { + overflowed_ = true; + return {}; + } + new (slot.ptr()) VariantData(); + return slot; + } + + void freeVariant(Slot slot) { + variantPools_.freeSlot(slot); + } + + VariantData* getVariant(SlotId id) const { + return variantPools_.getSlot(id); + } #if ARDUINOJSON_USE_8_BYTE_POOL - Slot allocEightByte(); - void freeEightByte(SlotId slot); - EightByteValue* getEightByte(SlotId id) const; + Slot allocEightByte() { + auto slot = eightBytePools_.allocSlot(allocator_); + if (!slot) { + overflowed_ = true; + return {}; + } + return slot; + } + + void freeEightByte(SlotId id) { + auto p = getEightByte(id); + eightBytePools_.freeSlot({p, id}); + } + + EightByteValue* getEightByte(SlotId id) const { + return eightBytePools_.getSlot(id); + } #endif template diff --git a/src/ArduinoJson/Memory/ResourceManagerImpl.hpp b/src/ArduinoJson/Memory/ResourceManagerImpl.hpp deleted file mode 100644 index 2c7776d8..00000000 --- a/src/ArduinoJson/Memory/ResourceManagerImpl.hpp +++ /dev/null @@ -1,50 +0,0 @@ -// ArduinoJson - https://arduinojson.org -// Copyright © 2014-2025, Benoit BLANCHON -// MIT License - -#pragma once - -#include -#include - -ARDUINOJSON_BEGIN_PRIVATE_NAMESPACE - -inline Slot ResourceManager::allocVariant() { - auto slot = variantPools_.allocSlot(allocator_); - if (!slot) { - overflowed_ = true; - return {}; - } - new (slot.ptr()) VariantData(); - return slot; -} - -inline void ResourceManager::freeVariant(Slot slot) { - variantPools_.freeSlot(slot); -} - -inline VariantData* ResourceManager::getVariant(SlotId id) const { - return reinterpret_cast(variantPools_.getSlot(id)); -} - -#if ARDUINOJSON_USE_8_BYTE_POOL -inline Slot ResourceManager::allocEightByte() { - auto slot = eightBytePools_.allocSlot(allocator_); - if (!slot) { - overflowed_ = true; - return {}; - } - return slot; -} - -inline void ResourceManager::freeEightByte(SlotId id) { - auto p = getEightByte(id); - eightBytePools_.freeSlot({p, id}); -} - -inline EightByteValue* ResourceManager::getEightByte(SlotId id) const { - return eightBytePools_.getSlot(id); -} -#endif - -ARDUINOJSON_END_PRIVATE_NAMESPACE