forked from bblanchon/ArduinoJson
Remove VariantSlot
This commit is contained in:
@ -10,8 +10,8 @@ static_assert(ARDUINOJSON_LITTLE_ENDIAN == 1, "ARDUINOJSON_LITTLE_ENDIAN");
|
||||
|
||||
static_assert(ARDUINOJSON_USE_DOUBLE == 1, "ARDUINOJSON_USE_DOUBLE");
|
||||
|
||||
static_assert(sizeof(ArduinoJson::detail::VariantSlot) == 6,
|
||||
"sizeof(VariantSlot)");
|
||||
static_assert(sizeof(ArduinoJson::detail::VariantData) == 6,
|
||||
"sizeof(VariantData)");
|
||||
|
||||
void setup() {}
|
||||
void loop() {}
|
||||
|
@ -8,8 +8,8 @@ static_assert(ARDUINOJSON_LITTLE_ENDIAN == 1, "ARDUINOJSON_LITTLE_ENDIAN");
|
||||
|
||||
static_assert(ARDUINOJSON_USE_DOUBLE == 1, "ARDUINOJSON_USE_DOUBLE");
|
||||
|
||||
static_assert(sizeof(ArduinoJson::detail::VariantSlot) == 16,
|
||||
"sizeof(VariantSlot)");
|
||||
static_assert(sizeof(ArduinoJson::detail::VariantData) == 16,
|
||||
"sizeof(VariantData)");
|
||||
|
||||
void setup() {}
|
||||
void loop() {}
|
||||
|
@ -8,7 +8,7 @@ static_assert(ARDUINOJSON_LITTLE_ENDIAN == 1, "ARDUINOJSON_LITTLE_ENDIAN");
|
||||
|
||||
static_assert(ARDUINOJSON_USE_DOUBLE == 1, "ARDUINOJSON_USE_DOUBLE");
|
||||
|
||||
static_assert(sizeof(ArduinoJson::detail::VariantSlot) == 12,
|
||||
"sizeof(VariantSlot)");
|
||||
static_assert(sizeof(ArduinoJson::detail::VariantData) == 12,
|
||||
"sizeof(VariantData)");
|
||||
|
||||
int main() {}
|
||||
|
@ -8,7 +8,7 @@ static_assert(ARDUINOJSON_LITTLE_ENDIAN == 1, "ARDUINOJSON_LITTLE_ENDIAN");
|
||||
|
||||
static_assert(ARDUINOJSON_USE_DOUBLE == 1, "ARDUINOJSON_USE_DOUBLE");
|
||||
|
||||
static_assert(sizeof(ArduinoJson::detail::VariantSlot) == 16,
|
||||
"sizeof(VariantSlot)");
|
||||
static_assert(sizeof(ArduinoJson::detail::VariantData) == 16,
|
||||
"sizeof(VariantData)");
|
||||
|
||||
int main() {}
|
||||
|
@ -8,7 +8,7 @@ static_assert(ARDUINOJSON_LITTLE_ENDIAN == 1, "ARDUINOJSON_LITTLE_ENDIAN");
|
||||
|
||||
static_assert(ARDUINOJSON_USE_DOUBLE == 1, "ARDUINOJSON_USE_DOUBLE");
|
||||
|
||||
static_assert(sizeof(ArduinoJson::detail::VariantSlot) == 16,
|
||||
"sizeof(VariantSlot)");
|
||||
static_assert(sizeof(ArduinoJson::detail::VariantData) == 16,
|
||||
"sizeof(VariantData)");
|
||||
|
||||
int main() {}
|
||||
|
@ -8,7 +8,7 @@ static_assert(ARDUINOJSON_LITTLE_ENDIAN == 1, "ARDUINOJSON_LITTLE_ENDIAN");
|
||||
|
||||
static_assert(ARDUINOJSON_USE_DOUBLE == 1, "ARDUINOJSON_USE_DOUBLE");
|
||||
|
||||
static_assert(sizeof(ArduinoJson::detail::VariantSlot) == 16,
|
||||
"sizeof(VariantSlot)");
|
||||
static_assert(sizeof(ArduinoJson::detail::VariantData) == 16,
|
||||
"sizeof(VariantData)");
|
||||
|
||||
int main() {}
|
||||
|
@ -29,7 +29,7 @@ TEST_CASE("ResourceManager::shrinkToFit()") {
|
||||
REQUIRE(spyingAllocator.log() ==
|
||||
AllocatorLog{
|
||||
Allocate(sizeofPool()),
|
||||
Reallocate(sizeofPool(), sizeof(VariantSlot)),
|
||||
Reallocate(sizeofPool(), sizeof(VariantData)),
|
||||
});
|
||||
}
|
||||
|
||||
@ -50,7 +50,7 @@ TEST_CASE("ResourceManager::shrinkToFit()") {
|
||||
|
||||
REQUIRE(spyingAllocator.log() ==
|
||||
AllocatorLog{
|
||||
Reallocate(sizeofPool(), sizeof(VariantSlot)),
|
||||
Reallocate(sizeofPool(), sizeof(VariantData)),
|
||||
Reallocate(sizeofPoolList(ARDUINOJSON_INITIAL_POOL_COUNT * 2),
|
||||
sizeofPoolList(ARDUINOJSON_INITIAL_POOL_COUNT + 1)),
|
||||
});
|
||||
|
@ -6,7 +6,7 @@
|
||||
|
||||
#include <ArduinoJson/Array/ArrayData.hpp>
|
||||
#include <ArduinoJson/Variant/VariantCompare.hpp>
|
||||
#include <ArduinoJson/Variant/VariantSlot.hpp>
|
||||
#include <ArduinoJson/Variant/VariantData.hpp>
|
||||
|
||||
ARDUINOJSON_BEGIN_PRIVATE_NAMESPACE
|
||||
|
||||
@ -73,7 +73,7 @@ inline bool ArrayData::addValue(T&& value, ResourceManager* resources) {
|
||||
|
||||
// Returns the size (in bytes) of an array with n elements.
|
||||
constexpr size_t sizeofArray(size_t n) {
|
||||
return n * sizeof(VariantSlot);
|
||||
return n * sizeof(VariantData);
|
||||
}
|
||||
|
||||
ARDUINOJSON_END_PRIVATE_NAMESPACE
|
||||
|
@ -4,6 +4,7 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <ArduinoJson/Memory/ResourceManager.hpp>
|
||||
#include <ArduinoJson/Namespace.hpp>
|
||||
#include <ArduinoJson/Polyfills/assert.hpp>
|
||||
|
||||
@ -12,7 +13,6 @@
|
||||
ARDUINOJSON_BEGIN_PRIVATE_NAMESPACE
|
||||
|
||||
class VariantData;
|
||||
union VariantSlot;
|
||||
|
||||
class CollectionIterator {
|
||||
friend class CollectionData;
|
||||
|
@ -10,7 +10,7 @@
|
||||
|
||||
ARDUINOJSON_BEGIN_PRIVATE_NAMESPACE
|
||||
|
||||
union VariantSlot;
|
||||
class VariantData;
|
||||
using SlotId = uint_t<ARDUINOJSON_SLOT_ID_SIZE * 8>;
|
||||
using SlotCount = SlotId;
|
||||
const SlotId NULL_SLOT = SlotId(-1);
|
||||
@ -18,7 +18,7 @@ const SlotId NULL_SLOT = SlotId(-1);
|
||||
class SlotWithId {
|
||||
public:
|
||||
SlotWithId() : slot_(nullptr), id_(NULL_SLOT) {}
|
||||
SlotWithId(VariantSlot* slot, SlotId id) : slot_(slot), id_(id) {
|
||||
SlotWithId(VariantData* slot, SlotId id) : slot_(slot), id_(id) {
|
||||
ARDUINOJSON_ASSERT((slot == nullptr) == (id == NULL_SLOT));
|
||||
}
|
||||
|
||||
@ -30,17 +30,17 @@ class SlotWithId {
|
||||
return id_;
|
||||
}
|
||||
|
||||
VariantSlot* slot() const {
|
||||
VariantData* slot() const {
|
||||
return slot_;
|
||||
}
|
||||
|
||||
VariantSlot* operator->() {
|
||||
VariantData* operator->() {
|
||||
ARDUINOJSON_ASSERT(slot_ != nullptr);
|
||||
return slot_;
|
||||
}
|
||||
|
||||
private:
|
||||
VariantSlot* slot_;
|
||||
VariantData* slot_;
|
||||
SlotId id_;
|
||||
};
|
||||
|
||||
@ -50,7 +50,7 @@ class MemoryPool {
|
||||
void destroy(Allocator* allocator);
|
||||
|
||||
SlotWithId allocSlot();
|
||||
VariantSlot* getSlot(SlotId id) const;
|
||||
VariantData* getSlot(SlotId id) const;
|
||||
void clear();
|
||||
void shrinkToFit(Allocator*);
|
||||
SlotCount usage() const;
|
||||
@ -61,7 +61,7 @@ class MemoryPool {
|
||||
private:
|
||||
SlotCount capacity_;
|
||||
SlotCount usage_;
|
||||
VariantSlot* slots_;
|
||||
VariantData* slots_;
|
||||
};
|
||||
|
||||
ARDUINOJSON_END_PRIVATE_NAMESPACE
|
||||
|
@ -5,14 +5,14 @@
|
||||
#pragma once
|
||||
|
||||
#include <ArduinoJson/Memory/MemoryPool.hpp>
|
||||
#include <ArduinoJson/Variant/VariantSlot.hpp>
|
||||
#include <ArduinoJson/Variant/VariantData.hpp>
|
||||
|
||||
ARDUINOJSON_BEGIN_PRIVATE_NAMESPACE
|
||||
|
||||
inline void MemoryPool::create(SlotCount cap, Allocator* allocator) {
|
||||
ARDUINOJSON_ASSERT(cap > 0);
|
||||
slots_ =
|
||||
reinterpret_cast<VariantSlot*>(allocator->allocate(slotsToBytes(cap)));
|
||||
reinterpret_cast<VariantData*>(allocator->allocate(slotsToBytes(cap)));
|
||||
capacity_ = slots_ ? cap : 0;
|
||||
usage_ = 0;
|
||||
}
|
||||
@ -26,7 +26,7 @@ inline void MemoryPool::destroy(Allocator* allocator) {
|
||||
}
|
||||
|
||||
inline void MemoryPool::shrinkToFit(Allocator* allocator) {
|
||||
auto newSlots = reinterpret_cast<VariantSlot*>(
|
||||
auto newSlots = reinterpret_cast<VariantData*>(
|
||||
allocator->reallocate(slots_, slotsToBytes(usage_)));
|
||||
if (newSlots) {
|
||||
slots_ = newSlots;
|
||||
@ -44,7 +44,7 @@ inline SlotWithId MemoryPool::allocSlot() {
|
||||
return {slot, SlotId(index)};
|
||||
}
|
||||
|
||||
inline VariantSlot* MemoryPool::getSlot(SlotId id) const {
|
||||
inline VariantData* MemoryPool::getSlot(SlotId id) const {
|
||||
ARDUINOJSON_ASSERT(id < usage_);
|
||||
return &slots_[id];
|
||||
}
|
||||
@ -58,11 +58,11 @@ inline void MemoryPool::clear() {
|
||||
}
|
||||
|
||||
inline SlotCount MemoryPool::bytesToSlots(size_t n) {
|
||||
return static_cast<SlotCount>(n / sizeof(VariantSlot));
|
||||
return static_cast<SlotCount>(n / sizeof(VariantData));
|
||||
}
|
||||
|
||||
inline size_t MemoryPool::slotsToBytes(SlotCount n) {
|
||||
return n * sizeof(VariantSlot);
|
||||
return n * sizeof(VariantData);
|
||||
}
|
||||
|
||||
inline SlotWithId MemoryPoolList::allocFromFreeList() {
|
||||
|
@ -97,7 +97,7 @@ class MemoryPoolList {
|
||||
|
||||
void freeSlot(SlotWithId slot);
|
||||
|
||||
VariantSlot* getSlot(SlotId id) const {
|
||||
VariantData* getSlot(SlotId id) const {
|
||||
if (id == NULL_SLOT)
|
||||
return nullptr;
|
||||
auto poolIndex = SlotId(id / ARDUINOJSON_POOL_CAPACITY);
|
||||
|
@ -13,7 +13,6 @@
|
||||
|
||||
ARDUINOJSON_BEGIN_PRIVATE_NAMESPACE
|
||||
|
||||
union VariantSlot;
|
||||
class MemoryPool;
|
||||
class VariantData;
|
||||
class VariantWithId;
|
||||
|
@ -7,7 +7,6 @@
|
||||
#include <ArduinoJson/Collection/CollectionData.hpp>
|
||||
#include <ArduinoJson/Memory/ResourceManager.hpp>
|
||||
#include <ArduinoJson/Variant/VariantData.hpp>
|
||||
#include <ArduinoJson/Variant/VariantSlot.hpp>
|
||||
|
||||
ARDUINOJSON_BEGIN_PRIVATE_NAMESPACE
|
||||
|
||||
@ -17,7 +16,7 @@ inline VariantWithId ResourceManager::allocVariant() {
|
||||
overflowed_ = true;
|
||||
return {};
|
||||
}
|
||||
return {new (&p->variant) VariantData, p.id()};
|
||||
return {new (p.slot()) VariantData, p.id()};
|
||||
}
|
||||
|
||||
inline void ResourceManager::freeVariant(VariantWithId variant) {
|
||||
|
@ -12,7 +12,6 @@
|
||||
|
||||
ARDUINOJSON_BEGIN_PRIVATE_NAMESPACE
|
||||
|
||||
union VariantSlot;
|
||||
class MemoryPool;
|
||||
|
||||
class StringPool {
|
||||
|
@ -6,7 +6,7 @@
|
||||
|
||||
#include <ArduinoJson/Object/ObjectData.hpp>
|
||||
#include <ArduinoJson/Variant/VariantCompare.hpp>
|
||||
#include <ArduinoJson/Variant/VariantSlot.hpp>
|
||||
#include <ArduinoJson/Variant/VariantData.hpp>
|
||||
|
||||
ARDUINOJSON_BEGIN_PRIVATE_NAMESPACE
|
||||
|
||||
@ -70,7 +70,7 @@ inline VariantData* ObjectData::addMember(TAdaptedString key,
|
||||
|
||||
// Returns the size (in bytes) of an object with n members.
|
||||
constexpr size_t sizeofObject(size_t n) {
|
||||
return 2 * n * sizeof(VariantSlot);
|
||||
return 2 * n * sizeof(VariantData);
|
||||
}
|
||||
|
||||
ARDUINOJSON_END_PRIVATE_NAMESPACE
|
||||
|
@ -538,7 +538,7 @@ class VariantWithId : public SlotWithId {
|
||||
public:
|
||||
VariantWithId() {}
|
||||
VariantWithId(VariantData* data, SlotId id)
|
||||
: SlotWithId(reinterpret_cast<VariantSlot*>(data), id) {}
|
||||
: SlotWithId(reinterpret_cast<VariantData*>(data), id) {}
|
||||
|
||||
VariantData* data() {
|
||||
return reinterpret_cast<VariantData*>(slot());
|
||||
|
@ -1,22 +0,0 @@
|
||||
// ArduinoJson - https://arduinojson.org
|
||||
// Copyright © 2014-2024, Benoit BLANCHON
|
||||
// MIT License
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <ArduinoJson/Memory/ResourceManager.hpp>
|
||||
#include <ArduinoJson/Polyfills/limits.hpp>
|
||||
#include <ArduinoJson/Polyfills/type_traits.hpp>
|
||||
#include <ArduinoJson/Variant/VariantData.hpp>
|
||||
|
||||
ARDUINOJSON_BEGIN_PRIVATE_NAMESPACE
|
||||
|
||||
struct StringNode;
|
||||
|
||||
union VariantSlot {
|
||||
VariantSlot() {}
|
||||
|
||||
VariantData variant;
|
||||
};
|
||||
|
||||
ARDUINOJSON_END_PRIVATE_NAMESPACE
|
Reference in New Issue
Block a user