From 2be24eded8900188108fc6179b3cf245686950bd Mon Sep 17 00:00:00 2001 From: Benoit Blanchon Date: Sun, 25 Aug 2024 14:51:59 +0200 Subject: [PATCH] Rename `SlotWithId::slot()` and `VariantWithId::data()` to `ptr()` --- extras/tests/ResourceManager/allocVariant.cpp | 18 +++++++++--------- extras/tests/ResourceManager/swap.cpp | 16 ++++++++-------- src/ArduinoJson/Array/ArrayImpl.hpp | 4 ++-- src/ArduinoJson/Memory/MemoryPool.hpp | 2 +- src/ArduinoJson/Memory/MemoryPoolImpl.hpp | 2 +- src/ArduinoJson/Memory/MemoryPoolList.hpp | 2 +- src/ArduinoJson/Memory/ResourceManagerImpl.hpp | 2 +- src/ArduinoJson/Object/ObjectImpl.hpp | 2 +- src/ArduinoJson/Variant/VariantData.hpp | 8 ++++---- 9 files changed, 28 insertions(+), 28 deletions(-) diff --git a/extras/tests/ResourceManager/allocVariant.cpp b/extras/tests/ResourceManager/allocVariant.cpp index ec0ae91f..3cfadf35 100644 --- a/extras/tests/ResourceManager/allocVariant.cpp +++ b/extras/tests/ResourceManager/allocVariant.cpp @@ -14,11 +14,11 @@ TEST_CASE("ResourceManager::allocVariant()") { ResourceManager resources; auto s1 = resources.allocVariant(); - REQUIRE(s1.data() != nullptr); + REQUIRE(s1.ptr() != nullptr); auto s2 = resources.allocVariant(); - REQUIRE(s2.data() != nullptr); + REQUIRE(s2.ptr() != nullptr); - REQUIRE(s1.data() != s2.data()); + REQUIRE(s1.ptr() != s2.ptr()); } SECTION("Returns the same slot after calling freeVariant()") { @@ -42,8 +42,8 @@ TEST_CASE("ResourceManager::allocVariant()") { SECTION("Returns aligned pointers") { ResourceManager resources; - REQUIRE(isAligned(resources.allocVariant().data())); - REQUIRE(isAligned(resources.allocVariant().data())); + REQUIRE(isAligned(resources.allocVariant().ptr())); + REQUIRE(isAligned(resources.allocVariant().ptr())); } SECTION("Returns null if pool list allocation fails") { @@ -51,7 +51,7 @@ TEST_CASE("ResourceManager::allocVariant()") { auto variant = resources.allocVariant(); REQUIRE(variant.id() == NULL_SLOT); - REQUIRE(variant.data() == nullptr); + REQUIRE(variant.ptr() == nullptr); } SECTION("Returns null if pool allocation fails") { @@ -61,7 +61,7 @@ TEST_CASE("ResourceManager::allocVariant()") { auto variant = resources.allocVariant(); REQUIRE(variant.id() == NULL_SLOT); - REQUIRE(variant.data() == nullptr); + REQUIRE(variant.ptr() == nullptr); } SECTION("Try overflow pool counter") { @@ -75,7 +75,7 @@ TEST_CASE("ResourceManager::allocVariant()") { for (SlotId i = 0; i < NULL_SLOT; i++) { auto slot = resources.allocVariant(); REQUIRE(slot.id() == i); // or != NULL_SLOT - REQUIRE(slot.data() != nullptr); + REQUIRE(slot.ptr() != nullptr); } REQUIRE(resources.overflowed() == false); @@ -84,7 +84,7 @@ TEST_CASE("ResourceManager::allocVariant()") { for (int i = 0; i < 10; i++) { auto slot = resources.allocVariant(); REQUIRE(slot.id() == NULL_SLOT); - REQUIRE(slot.data() == nullptr); + REQUIRE(slot.ptr() == nullptr); } REQUIRE(resources.overflowed() == true); diff --git a/extras/tests/ResourceManager/swap.cpp b/extras/tests/ResourceManager/swap.cpp index b52e05aa..50517d48 100644 --- a/extras/tests/ResourceManager/swap.cpp +++ b/extras/tests/ResourceManager/swap.cpp @@ -29,8 +29,8 @@ TEST_CASE("ResourceManager::swap()") { swap(a, b); - REQUIRE(a1.data() == b.getVariant(a1.id())); - REQUIRE(b1.data() == a.getVariant(b1.id())); + REQUIRE(a1.ptr() == b.getVariant(a1.id())); + REQUIRE(b1.ptr() == a.getVariant(b1.id())); REQUIRE(spy.log() == AllocatorLog{ Allocate(sizeofPool()) * 2, @@ -47,8 +47,8 @@ TEST_CASE("ResourceManager::swap()") { auto b1 = b.allocVariant(); swap(a, b); - REQUIRE(a1.data() == b.getVariant(a1.id())); - REQUIRE(b1.data() == a.getVariant(b1.id())); + REQUIRE(a1.ptr() == b.getVariant(a1.id())); + REQUIRE(b1.ptr() == a.getVariant(b1.id())); REQUIRE(spy.log() == AllocatorLog{ @@ -68,8 +68,8 @@ TEST_CASE("ResourceManager::swap()") { auto b1 = b.allocVariant(); swap(a, b); - REQUIRE(a1.data() == b.getVariant(a1.id())); - REQUIRE(b1.data() == a.getVariant(b1.id())); + REQUIRE(a1.ptr() == b.getVariant(a1.id())); + REQUIRE(b1.ptr() == a.getVariant(b1.id())); REQUIRE(spy.log() == AllocatorLog{ @@ -91,7 +91,7 @@ TEST_CASE("ResourceManager::swap()") { swap(a, b); - REQUIRE(a1.data() == b.getVariant(a1.id())); - REQUIRE(b1.data() == a.getVariant(b1.id())); + REQUIRE(a1.ptr() == b.getVariant(a1.id())); + REQUIRE(b1.ptr() == a.getVariant(b1.id())); } } diff --git a/src/ArduinoJson/Array/ArrayImpl.hpp b/src/ArduinoJson/Array/ArrayImpl.hpp index 8e6af227..d09aaa3f 100644 --- a/src/ArduinoJson/Array/ArrayImpl.hpp +++ b/src/ArduinoJson/Array/ArrayImpl.hpp @@ -25,7 +25,7 @@ inline VariantData* ArrayData::addElement(ResourceManager* resources) { if (!slot) return nullptr; CollectionData::appendOne(slot, resources); - return slot.data(); + return slot.ptr(); } inline VariantData* ArrayData::getOrAddElement(size_t index, @@ -62,7 +62,7 @@ inline bool ArrayData::addValue(T&& value, ResourceManager* resources) { auto slot = resources->allocVariant(); if (!slot) return false; - JsonVariant variant(slot.data(), resources); + JsonVariant variant(slot.ptr(), resources); if (!variant.set(detail::forward(value))) { resources->freeVariant(slot); return false; diff --git a/src/ArduinoJson/Memory/MemoryPool.hpp b/src/ArduinoJson/Memory/MemoryPool.hpp index 35e623c8..d7062b3a 100644 --- a/src/ArduinoJson/Memory/MemoryPool.hpp +++ b/src/ArduinoJson/Memory/MemoryPool.hpp @@ -30,7 +30,7 @@ class SlotWithId { return id_; } - VariantData* slot() const { + VariantData* ptr() const { return slot_; } diff --git a/src/ArduinoJson/Memory/MemoryPoolImpl.hpp b/src/ArduinoJson/Memory/MemoryPoolImpl.hpp index d9ba7a58..059ef788 100644 --- a/src/ArduinoJson/Memory/MemoryPoolImpl.hpp +++ b/src/ArduinoJson/Memory/MemoryPoolImpl.hpp @@ -74,7 +74,7 @@ inline SlotWithId MemoryPoolList::allocFromFreeList() { } inline void MemoryPoolList::freeSlot(SlotWithId slot) { - reinterpret_cast(slot.slot())->next = freeList_; + reinterpret_cast(slot.ptr())->next = freeList_; freeList_ = slot.id(); } diff --git a/src/ArduinoJson/Memory/MemoryPoolList.hpp b/src/ArduinoJson/Memory/MemoryPoolList.hpp index 96c1cc64..27fe57c4 100644 --- a/src/ArduinoJson/Memory/MemoryPoolList.hpp +++ b/src/ArduinoJson/Memory/MemoryPoolList.hpp @@ -145,7 +145,7 @@ class MemoryPoolList { auto slot = pools_[poolIndex].allocSlot(); if (!slot) return {}; - return {slot.slot(), + return {slot.ptr(), SlotId(poolIndex * ARDUINOJSON_POOL_CAPACITY + slot.id())}; } diff --git a/src/ArduinoJson/Memory/ResourceManagerImpl.hpp b/src/ArduinoJson/Memory/ResourceManagerImpl.hpp index c1c949e6..0deb5729 100644 --- a/src/ArduinoJson/Memory/ResourceManagerImpl.hpp +++ b/src/ArduinoJson/Memory/ResourceManagerImpl.hpp @@ -16,7 +16,7 @@ inline VariantWithId ResourceManager::allocVariant() { overflowed_ = true; return {}; } - return {new (p.slot()) VariantData, p.id()}; + return {new (p.ptr()) VariantData, p.id()}; } inline void ResourceManager::freeVariant(VariantWithId variant) { diff --git a/src/ArduinoJson/Object/ObjectImpl.hpp b/src/ArduinoJson/Object/ObjectImpl.hpp index b2280c4a..a5354d1d 100644 --- a/src/ArduinoJson/Object/ObjectImpl.hpp +++ b/src/ArduinoJson/Object/ObjectImpl.hpp @@ -65,7 +65,7 @@ inline VariantData* ObjectData::addMember(TAdaptedString key, CollectionData::appendPair(keySlot, valueSlot, resources); - return valueSlot.data(); + return valueSlot.ptr(); } // Returns the size (in bytes) of an object with n members. diff --git a/src/ArduinoJson/Variant/VariantData.hpp b/src/ArduinoJson/Variant/VariantData.hpp index 4a676cbe..f36fcaf0 100644 --- a/src/ArduinoJson/Variant/VariantData.hpp +++ b/src/ArduinoJson/Variant/VariantData.hpp @@ -540,13 +540,13 @@ class VariantWithId : public SlotWithId { VariantWithId(VariantData* data, SlotId id) : SlotWithId(reinterpret_cast(data), id) {} - VariantData* data() { - return reinterpret_cast(slot()); + VariantData* ptr() { + return reinterpret_cast(SlotWithId::ptr()); } VariantData* operator->() { - ARDUINOJSON_ASSERT(data() != nullptr); - return data(); + ARDUINOJSON_ASSERT(ptr() != nullptr); + return ptr(); } };