mirror of
https://github.com/bblanchon/ArduinoJson.git
synced 2025-07-29 10:17:39 +02:00
Rename SlotWithId::slot()
and VariantWithId::data()
to ptr()
This commit is contained in:
@ -14,11 +14,11 @@ TEST_CASE("ResourceManager::allocVariant()") {
|
|||||||
ResourceManager resources;
|
ResourceManager resources;
|
||||||
|
|
||||||
auto s1 = resources.allocVariant();
|
auto s1 = resources.allocVariant();
|
||||||
REQUIRE(s1.data() != nullptr);
|
REQUIRE(s1.ptr() != nullptr);
|
||||||
auto s2 = resources.allocVariant();
|
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()") {
|
SECTION("Returns the same slot after calling freeVariant()") {
|
||||||
@ -42,8 +42,8 @@ TEST_CASE("ResourceManager::allocVariant()") {
|
|||||||
SECTION("Returns aligned pointers") {
|
SECTION("Returns aligned pointers") {
|
||||||
ResourceManager resources;
|
ResourceManager resources;
|
||||||
|
|
||||||
REQUIRE(isAligned(resources.allocVariant().data()));
|
REQUIRE(isAligned(resources.allocVariant().ptr()));
|
||||||
REQUIRE(isAligned(resources.allocVariant().data()));
|
REQUIRE(isAligned(resources.allocVariant().ptr()));
|
||||||
}
|
}
|
||||||
|
|
||||||
SECTION("Returns null if pool list allocation fails") {
|
SECTION("Returns null if pool list allocation fails") {
|
||||||
@ -51,7 +51,7 @@ TEST_CASE("ResourceManager::allocVariant()") {
|
|||||||
|
|
||||||
auto variant = resources.allocVariant();
|
auto variant = resources.allocVariant();
|
||||||
REQUIRE(variant.id() == NULL_SLOT);
|
REQUIRE(variant.id() == NULL_SLOT);
|
||||||
REQUIRE(variant.data() == nullptr);
|
REQUIRE(variant.ptr() == nullptr);
|
||||||
}
|
}
|
||||||
|
|
||||||
SECTION("Returns null if pool allocation fails") {
|
SECTION("Returns null if pool allocation fails") {
|
||||||
@ -61,7 +61,7 @@ TEST_CASE("ResourceManager::allocVariant()") {
|
|||||||
|
|
||||||
auto variant = resources.allocVariant();
|
auto variant = resources.allocVariant();
|
||||||
REQUIRE(variant.id() == NULL_SLOT);
|
REQUIRE(variant.id() == NULL_SLOT);
|
||||||
REQUIRE(variant.data() == nullptr);
|
REQUIRE(variant.ptr() == nullptr);
|
||||||
}
|
}
|
||||||
|
|
||||||
SECTION("Try overflow pool counter") {
|
SECTION("Try overflow pool counter") {
|
||||||
@ -75,7 +75,7 @@ TEST_CASE("ResourceManager::allocVariant()") {
|
|||||||
for (SlotId i = 0; i < NULL_SLOT; i++) {
|
for (SlotId i = 0; i < NULL_SLOT; i++) {
|
||||||
auto slot = resources.allocVariant();
|
auto slot = resources.allocVariant();
|
||||||
REQUIRE(slot.id() == i); // or != NULL_SLOT
|
REQUIRE(slot.id() == i); // or != NULL_SLOT
|
||||||
REQUIRE(slot.data() != nullptr);
|
REQUIRE(slot.ptr() != nullptr);
|
||||||
}
|
}
|
||||||
|
|
||||||
REQUIRE(resources.overflowed() == false);
|
REQUIRE(resources.overflowed() == false);
|
||||||
@ -84,7 +84,7 @@ TEST_CASE("ResourceManager::allocVariant()") {
|
|||||||
for (int i = 0; i < 10; i++) {
|
for (int i = 0; i < 10; i++) {
|
||||||
auto slot = resources.allocVariant();
|
auto slot = resources.allocVariant();
|
||||||
REQUIRE(slot.id() == NULL_SLOT);
|
REQUIRE(slot.id() == NULL_SLOT);
|
||||||
REQUIRE(slot.data() == nullptr);
|
REQUIRE(slot.ptr() == nullptr);
|
||||||
}
|
}
|
||||||
|
|
||||||
REQUIRE(resources.overflowed() == true);
|
REQUIRE(resources.overflowed() == true);
|
||||||
|
@ -29,8 +29,8 @@ TEST_CASE("ResourceManager::swap()") {
|
|||||||
|
|
||||||
swap(a, b);
|
swap(a, b);
|
||||||
|
|
||||||
REQUIRE(a1.data() == b.getVariant(a1.id()));
|
REQUIRE(a1.ptr() == b.getVariant(a1.id()));
|
||||||
REQUIRE(b1.data() == a.getVariant(b1.id()));
|
REQUIRE(b1.ptr() == a.getVariant(b1.id()));
|
||||||
|
|
||||||
REQUIRE(spy.log() == AllocatorLog{
|
REQUIRE(spy.log() == AllocatorLog{
|
||||||
Allocate(sizeofPool()) * 2,
|
Allocate(sizeofPool()) * 2,
|
||||||
@ -47,8 +47,8 @@ TEST_CASE("ResourceManager::swap()") {
|
|||||||
auto b1 = b.allocVariant();
|
auto b1 = b.allocVariant();
|
||||||
swap(a, b);
|
swap(a, b);
|
||||||
|
|
||||||
REQUIRE(a1.data() == b.getVariant(a1.id()));
|
REQUIRE(a1.ptr() == b.getVariant(a1.id()));
|
||||||
REQUIRE(b1.data() == a.getVariant(b1.id()));
|
REQUIRE(b1.ptr() == a.getVariant(b1.id()));
|
||||||
|
|
||||||
REQUIRE(spy.log() ==
|
REQUIRE(spy.log() ==
|
||||||
AllocatorLog{
|
AllocatorLog{
|
||||||
@ -68,8 +68,8 @@ TEST_CASE("ResourceManager::swap()") {
|
|||||||
auto b1 = b.allocVariant();
|
auto b1 = b.allocVariant();
|
||||||
swap(a, b);
|
swap(a, b);
|
||||||
|
|
||||||
REQUIRE(a1.data() == b.getVariant(a1.id()));
|
REQUIRE(a1.ptr() == b.getVariant(a1.id()));
|
||||||
REQUIRE(b1.data() == a.getVariant(b1.id()));
|
REQUIRE(b1.ptr() == a.getVariant(b1.id()));
|
||||||
|
|
||||||
REQUIRE(spy.log() ==
|
REQUIRE(spy.log() ==
|
||||||
AllocatorLog{
|
AllocatorLog{
|
||||||
@ -91,7 +91,7 @@ TEST_CASE("ResourceManager::swap()") {
|
|||||||
|
|
||||||
swap(a, b);
|
swap(a, b);
|
||||||
|
|
||||||
REQUIRE(a1.data() == b.getVariant(a1.id()));
|
REQUIRE(a1.ptr() == b.getVariant(a1.id()));
|
||||||
REQUIRE(b1.data() == a.getVariant(b1.id()));
|
REQUIRE(b1.ptr() == a.getVariant(b1.id()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -25,7 +25,7 @@ inline VariantData* ArrayData::addElement(ResourceManager* resources) {
|
|||||||
if (!slot)
|
if (!slot)
|
||||||
return nullptr;
|
return nullptr;
|
||||||
CollectionData::appendOne(slot, resources);
|
CollectionData::appendOne(slot, resources);
|
||||||
return slot.data();
|
return slot.ptr();
|
||||||
}
|
}
|
||||||
|
|
||||||
inline VariantData* ArrayData::getOrAddElement(size_t index,
|
inline VariantData* ArrayData::getOrAddElement(size_t index,
|
||||||
@ -62,7 +62,7 @@ inline bool ArrayData::addValue(T&& value, ResourceManager* resources) {
|
|||||||
auto slot = resources->allocVariant();
|
auto slot = resources->allocVariant();
|
||||||
if (!slot)
|
if (!slot)
|
||||||
return false;
|
return false;
|
||||||
JsonVariant variant(slot.data(), resources);
|
JsonVariant variant(slot.ptr(), resources);
|
||||||
if (!variant.set(detail::forward<T>(value))) {
|
if (!variant.set(detail::forward<T>(value))) {
|
||||||
resources->freeVariant(slot);
|
resources->freeVariant(slot);
|
||||||
return false;
|
return false;
|
||||||
|
@ -30,7 +30,7 @@ class SlotWithId {
|
|||||||
return id_;
|
return id_;
|
||||||
}
|
}
|
||||||
|
|
||||||
VariantData* slot() const {
|
VariantData* ptr() const {
|
||||||
return slot_;
|
return slot_;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -74,7 +74,7 @@ inline SlotWithId MemoryPoolList::allocFromFreeList() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
inline void MemoryPoolList::freeSlot(SlotWithId slot) {
|
inline void MemoryPoolList::freeSlot(SlotWithId slot) {
|
||||||
reinterpret_cast<FreeSlot*>(slot.slot())->next = freeList_;
|
reinterpret_cast<FreeSlot*>(slot.ptr())->next = freeList_;
|
||||||
freeList_ = slot.id();
|
freeList_ = slot.id();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -145,7 +145,7 @@ class MemoryPoolList {
|
|||||||
auto slot = pools_[poolIndex].allocSlot();
|
auto slot = pools_[poolIndex].allocSlot();
|
||||||
if (!slot)
|
if (!slot)
|
||||||
return {};
|
return {};
|
||||||
return {slot.slot(),
|
return {slot.ptr(),
|
||||||
SlotId(poolIndex * ARDUINOJSON_POOL_CAPACITY + slot.id())};
|
SlotId(poolIndex * ARDUINOJSON_POOL_CAPACITY + slot.id())};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -16,7 +16,7 @@ inline VariantWithId ResourceManager::allocVariant() {
|
|||||||
overflowed_ = true;
|
overflowed_ = true;
|
||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
return {new (p.slot()) VariantData, p.id()};
|
return {new (p.ptr()) VariantData, p.id()};
|
||||||
}
|
}
|
||||||
|
|
||||||
inline void ResourceManager::freeVariant(VariantWithId variant) {
|
inline void ResourceManager::freeVariant(VariantWithId variant) {
|
||||||
|
@ -65,7 +65,7 @@ inline VariantData* ObjectData::addMember(TAdaptedString key,
|
|||||||
|
|
||||||
CollectionData::appendPair(keySlot, valueSlot, resources);
|
CollectionData::appendPair(keySlot, valueSlot, resources);
|
||||||
|
|
||||||
return valueSlot.data();
|
return valueSlot.ptr();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Returns the size (in bytes) of an object with n members.
|
// Returns the size (in bytes) of an object with n members.
|
||||||
|
@ -540,13 +540,13 @@ class VariantWithId : public SlotWithId {
|
|||||||
VariantWithId(VariantData* data, SlotId id)
|
VariantWithId(VariantData* data, SlotId id)
|
||||||
: SlotWithId(reinterpret_cast<VariantData*>(data), id) {}
|
: SlotWithId(reinterpret_cast<VariantData*>(data), id) {}
|
||||||
|
|
||||||
VariantData* data() {
|
VariantData* ptr() {
|
||||||
return reinterpret_cast<VariantData*>(slot());
|
return reinterpret_cast<VariantData*>(SlotWithId::ptr());
|
||||||
}
|
}
|
||||||
|
|
||||||
VariantData* operator->() {
|
VariantData* operator->() {
|
||||||
ARDUINOJSON_ASSERT(data() != nullptr);
|
ARDUINOJSON_ASSERT(ptr() != nullptr);
|
||||||
return data();
|
return ptr();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user