Hide FreeSlot in MemoryPoolList

This commit is contained in:
Benoit Blanchon
2024-08-25 14:39:18 +02:00
parent cec18177b0
commit f7f1b9745d
3 changed files with 6 additions and 7 deletions

View File

@ -69,12 +69,12 @@ inline SlotWithId MemoryPoolList::allocFromFreeList() {
ARDUINOJSON_ASSERT(freeList_ != NULL_SLOT); ARDUINOJSON_ASSERT(freeList_ != NULL_SLOT);
auto id = freeList_; auto id = freeList_;
auto slot = getSlot(freeList_); auto slot = getSlot(freeList_);
freeList_ = slot->free.next; freeList_ = reinterpret_cast<FreeSlot*>(slot)->next;
return {slot, id}; return {slot, id};
} }
inline void MemoryPoolList::freeSlot(SlotWithId slot) { inline void MemoryPoolList::freeSlot(SlotWithId slot) {
slot->free.next = freeList_; reinterpret_cast<FreeSlot*>(slot.slot())->next = freeList_;
freeList_ = slot.id(); freeList_ = slot.id();
} }

View File

@ -15,6 +15,10 @@ ARDUINOJSON_BEGIN_PRIVATE_NAMESPACE
using PoolCount = SlotId; using PoolCount = SlotId;
class MemoryPoolList { class MemoryPoolList {
struct FreeSlot {
SlotId next;
};
public: public:
MemoryPoolList() = default; MemoryPoolList() = default;

View File

@ -13,15 +13,10 @@ ARDUINOJSON_BEGIN_PRIVATE_NAMESPACE
struct StringNode; struct StringNode;
struct FreeSlot {
SlotId next;
};
union VariantSlot { union VariantSlot {
VariantSlot() {} VariantSlot() {}
VariantData variant; VariantData variant;
FreeSlot free;
}; };
ARDUINOJSON_END_PRIVATE_NAMESPACE ARDUINOJSON_END_PRIVATE_NAMESPACE