diff --git a/src/ArduinoJson/Collection/CollectionData.hpp b/src/ArduinoJson/Collection/CollectionData.hpp index a1c575c7..5817c7a4 100644 --- a/src/ArduinoJson/Collection/CollectionData.hpp +++ b/src/ArduinoJson/Collection/CollectionData.hpp @@ -97,17 +97,15 @@ class CollectionData { } protected: - void appendOne(SlotWithId slot, - const ResourceManager* resources); - void appendPair(SlotWithId key, SlotWithId value, + void appendOne(Slot slot, const ResourceManager* resources); + void appendPair(Slot key, Slot value, const ResourceManager* resources); void removeOne(iterator it, ResourceManager* resources); void removePair(iterator it, ResourceManager* resources); private: - SlotWithId getPreviousSlot(VariantData*, - const ResourceManager*) const; + Slot getPreviousSlot(VariantData*, const ResourceManager*) const; }; inline const VariantData* collectionToVariant( diff --git a/src/ArduinoJson/Collection/CollectionImpl.hpp b/src/ArduinoJson/Collection/CollectionImpl.hpp index 4c022b9c..c0a650c0 100644 --- a/src/ArduinoJson/Collection/CollectionImpl.hpp +++ b/src/ArduinoJson/Collection/CollectionImpl.hpp @@ -30,7 +30,7 @@ inline CollectionData::iterator CollectionData::createIterator( return iterator(resources->getVariant(head_), head_); } -inline void CollectionData::appendOne(SlotWithId slot, +inline void CollectionData::appendOne(Slot slot, const ResourceManager* resources) { if (tail_ != NULL_SLOT) { auto tail = resources->getVariant(tail_); @@ -42,8 +42,8 @@ inline void CollectionData::appendOne(SlotWithId slot, } } -inline void CollectionData::appendPair(SlotWithId key, - SlotWithId value, +inline void CollectionData::appendPair(Slot key, + Slot value, const ResourceManager* resources) { key->setNext(value.id()); @@ -63,22 +63,22 @@ inline void CollectionData::clear(ResourceManager* resources) { auto currId = next; auto slot = resources->getVariant(next); next = slot->next(); - resources->freeVariant(SlotWithId(slot, currId)); + resources->freeVariant({slot, currId}); } head_ = NULL_SLOT; tail_ = NULL_SLOT; } -inline SlotWithId CollectionData::getPreviousSlot( +inline Slot CollectionData::getPreviousSlot( VariantData* target, const ResourceManager* resources) const { - auto prev = SlotWithId(); + auto prev = Slot(); auto currentId = head_; while (currentId != NULL_SLOT) { auto currentSlot = resources->getVariant(currentId); if (currentSlot == target) break; - prev = SlotWithId(currentSlot, currentId); + prev = Slot(currentSlot, currentId); currentId = currentSlot->next(); } return prev; diff --git a/src/ArduinoJson/Memory/MemoryPool.hpp b/src/ArduinoJson/Memory/MemoryPool.hpp index 742e9d7b..baa988f0 100644 --- a/src/ArduinoJson/Memory/MemoryPool.hpp +++ b/src/ArduinoJson/Memory/MemoryPool.hpp @@ -15,15 +15,15 @@ using SlotCount = SlotId; const SlotId NULL_SLOT = SlotId(-1); template -class SlotWithId { +class Slot { public: - SlotWithId() : slot_(nullptr), id_(NULL_SLOT) {} - SlotWithId(T* slot, SlotId id) : slot_(slot), id_(id) { - ARDUINOJSON_ASSERT((slot == nullptr) == (id == NULL_SLOT)); + Slot() : ptr_(nullptr), id_(NULL_SLOT) {} + Slot(T* p, SlotId id) : ptr_(p), id_(id) { + ARDUINOJSON_ASSERT((p == nullptr) == (id == NULL_SLOT)); } explicit operator bool() const { - return slot_ != nullptr; + return ptr_ != nullptr; } SlotId id() const { @@ -31,16 +31,16 @@ class SlotWithId { } T* ptr() const { - return slot_; + return ptr_; } T* operator->() const { - ARDUINOJSON_ASSERT(slot_ != nullptr); - return slot_; + ARDUINOJSON_ASSERT(ptr_ != nullptr); + return ptr_; } private: - T* slot_; + T* ptr_; SlotId id_; }; @@ -62,7 +62,7 @@ class MemoryPool { usage_ = 0; } - SlotWithId allocSlot() { + Slot allocSlot() { if (!slots_) return {}; if (usage_ >= capacity_) diff --git a/src/ArduinoJson/Memory/MemoryPoolList.hpp b/src/ArduinoJson/Memory/MemoryPoolList.hpp index 0aea4992..dc6503c7 100644 --- a/src/ArduinoJson/Memory/MemoryPoolList.hpp +++ b/src/ArduinoJson/Memory/MemoryPoolList.hpp @@ -79,7 +79,7 @@ class MemoryPoolList { return *this; } - SlotWithId allocSlot(Allocator* allocator) { + Slot allocSlot(Allocator* allocator) { // try to allocate from free list if (freeList_ != NULL_SLOT) { return allocFromFreeList(); @@ -100,7 +100,7 @@ class MemoryPoolList { return allocFromLastPool(); } - void freeSlot(SlotWithId slot) { + void freeSlot(Slot slot) { reinterpret_cast(slot.ptr())->next = freeList_; freeList_ = slot.id(); } @@ -149,7 +149,7 @@ class MemoryPoolList { } private: - SlotWithId allocFromFreeList() { + Slot allocFromFreeList() { ARDUINOJSON_ASSERT(freeList_ != NULL_SLOT); auto id = freeList_; auto slot = getSlot(freeList_); @@ -157,7 +157,7 @@ class MemoryPoolList { return {slot, id}; } - SlotWithId allocFromLastPool() { + Slot allocFromLastPool() { ARDUINOJSON_ASSERT(count_ > 0); auto poolIndex = SlotId(count_ - 1); auto slot = pools_[poolIndex].allocSlot(); diff --git a/src/ArduinoJson/Memory/ResourceManager.hpp b/src/ArduinoJson/Memory/ResourceManager.hpp index 7b23923e..e8e594b5 100644 --- a/src/ArduinoJson/Memory/ResourceManager.hpp +++ b/src/ArduinoJson/Memory/ResourceManager.hpp @@ -49,9 +49,9 @@ class ResourceManager { return overflowed_; } - SlotWithId allocVariant(); + Slot allocVariant(); - void freeVariant(SlotWithId slot); + void freeVariant(Slot slot); VariantData* getVariant(SlotId id) const; diff --git a/src/ArduinoJson/Memory/ResourceManagerImpl.hpp b/src/ArduinoJson/Memory/ResourceManagerImpl.hpp index 73200f45..db89a045 100644 --- a/src/ArduinoJson/Memory/ResourceManagerImpl.hpp +++ b/src/ArduinoJson/Memory/ResourceManagerImpl.hpp @@ -10,7 +10,7 @@ ARDUINOJSON_BEGIN_PRIVATE_NAMESPACE -inline SlotWithId ResourceManager::allocVariant() { +inline Slot ResourceManager::allocVariant() { auto p = variantPools_.allocSlot(allocator_); if (!p) { overflowed_ = true; @@ -19,7 +19,7 @@ inline SlotWithId ResourceManager::allocVariant() { return {new (p.ptr()) VariantData, p.id()}; } -inline void ResourceManager::freeVariant(SlotWithId variant) { +inline void ResourceManager::freeVariant(Slot variant) { variant->setNull(this); variantPools_.freeSlot(variant); }