mirror of
https://github.com/bblanchon/ArduinoJson.git
synced 2025-07-29 18:27:37 +02:00
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(ARDUINOJSON_USE_DOUBLE == 1, "ARDUINOJSON_USE_DOUBLE");
|
||||||
|
|
||||||
static_assert(sizeof(ArduinoJson::detail::VariantSlot) == 6,
|
static_assert(sizeof(ArduinoJson::detail::VariantData) == 6,
|
||||||
"sizeof(VariantSlot)");
|
"sizeof(VariantData)");
|
||||||
|
|
||||||
void setup() {}
|
void setup() {}
|
||||||
void loop() {}
|
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(ARDUINOJSON_USE_DOUBLE == 1, "ARDUINOJSON_USE_DOUBLE");
|
||||||
|
|
||||||
static_assert(sizeof(ArduinoJson::detail::VariantSlot) == 16,
|
static_assert(sizeof(ArduinoJson::detail::VariantData) == 16,
|
||||||
"sizeof(VariantSlot)");
|
"sizeof(VariantData)");
|
||||||
|
|
||||||
void setup() {}
|
void setup() {}
|
||||||
void loop() {}
|
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(ARDUINOJSON_USE_DOUBLE == 1, "ARDUINOJSON_USE_DOUBLE");
|
||||||
|
|
||||||
static_assert(sizeof(ArduinoJson::detail::VariantSlot) == 12,
|
static_assert(sizeof(ArduinoJson::detail::VariantData) == 12,
|
||||||
"sizeof(VariantSlot)");
|
"sizeof(VariantData)");
|
||||||
|
|
||||||
int main() {}
|
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(ARDUINOJSON_USE_DOUBLE == 1, "ARDUINOJSON_USE_DOUBLE");
|
||||||
|
|
||||||
static_assert(sizeof(ArduinoJson::detail::VariantSlot) == 16,
|
static_assert(sizeof(ArduinoJson::detail::VariantData) == 16,
|
||||||
"sizeof(VariantSlot)");
|
"sizeof(VariantData)");
|
||||||
|
|
||||||
int main() {}
|
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(ARDUINOJSON_USE_DOUBLE == 1, "ARDUINOJSON_USE_DOUBLE");
|
||||||
|
|
||||||
static_assert(sizeof(ArduinoJson::detail::VariantSlot) == 16,
|
static_assert(sizeof(ArduinoJson::detail::VariantData) == 16,
|
||||||
"sizeof(VariantSlot)");
|
"sizeof(VariantData)");
|
||||||
|
|
||||||
int main() {}
|
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(ARDUINOJSON_USE_DOUBLE == 1, "ARDUINOJSON_USE_DOUBLE");
|
||||||
|
|
||||||
static_assert(sizeof(ArduinoJson::detail::VariantSlot) == 16,
|
static_assert(sizeof(ArduinoJson::detail::VariantData) == 16,
|
||||||
"sizeof(VariantSlot)");
|
"sizeof(VariantData)");
|
||||||
|
|
||||||
int main() {}
|
int main() {}
|
||||||
|
@ -29,7 +29,7 @@ TEST_CASE("ResourceManager::shrinkToFit()") {
|
|||||||
REQUIRE(spyingAllocator.log() ==
|
REQUIRE(spyingAllocator.log() ==
|
||||||
AllocatorLog{
|
AllocatorLog{
|
||||||
Allocate(sizeofPool()),
|
Allocate(sizeofPool()),
|
||||||
Reallocate(sizeofPool(), sizeof(VariantSlot)),
|
Reallocate(sizeofPool(), sizeof(VariantData)),
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -50,7 +50,7 @@ TEST_CASE("ResourceManager::shrinkToFit()") {
|
|||||||
|
|
||||||
REQUIRE(spyingAllocator.log() ==
|
REQUIRE(spyingAllocator.log() ==
|
||||||
AllocatorLog{
|
AllocatorLog{
|
||||||
Reallocate(sizeofPool(), sizeof(VariantSlot)),
|
Reallocate(sizeofPool(), sizeof(VariantData)),
|
||||||
Reallocate(sizeofPoolList(ARDUINOJSON_INITIAL_POOL_COUNT * 2),
|
Reallocate(sizeofPoolList(ARDUINOJSON_INITIAL_POOL_COUNT * 2),
|
||||||
sizeofPoolList(ARDUINOJSON_INITIAL_POOL_COUNT + 1)),
|
sizeofPoolList(ARDUINOJSON_INITIAL_POOL_COUNT + 1)),
|
||||||
});
|
});
|
||||||
|
@ -6,7 +6,7 @@
|
|||||||
|
|
||||||
#include <ArduinoJson/Array/ArrayData.hpp>
|
#include <ArduinoJson/Array/ArrayData.hpp>
|
||||||
#include <ArduinoJson/Variant/VariantCompare.hpp>
|
#include <ArduinoJson/Variant/VariantCompare.hpp>
|
||||||
#include <ArduinoJson/Variant/VariantSlot.hpp>
|
#include <ArduinoJson/Variant/VariantData.hpp>
|
||||||
|
|
||||||
ARDUINOJSON_BEGIN_PRIVATE_NAMESPACE
|
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.
|
// Returns the size (in bytes) of an array with n elements.
|
||||||
constexpr size_t sizeofArray(size_t n) {
|
constexpr size_t sizeofArray(size_t n) {
|
||||||
return n * sizeof(VariantSlot);
|
return n * sizeof(VariantData);
|
||||||
}
|
}
|
||||||
|
|
||||||
ARDUINOJSON_END_PRIVATE_NAMESPACE
|
ARDUINOJSON_END_PRIVATE_NAMESPACE
|
||||||
|
@ -4,6 +4,7 @@
|
|||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
|
#include <ArduinoJson/Memory/ResourceManager.hpp>
|
||||||
#include <ArduinoJson/Namespace.hpp>
|
#include <ArduinoJson/Namespace.hpp>
|
||||||
#include <ArduinoJson/Polyfills/assert.hpp>
|
#include <ArduinoJson/Polyfills/assert.hpp>
|
||||||
|
|
||||||
@ -12,7 +13,6 @@
|
|||||||
ARDUINOJSON_BEGIN_PRIVATE_NAMESPACE
|
ARDUINOJSON_BEGIN_PRIVATE_NAMESPACE
|
||||||
|
|
||||||
class VariantData;
|
class VariantData;
|
||||||
union VariantSlot;
|
|
||||||
|
|
||||||
class CollectionIterator {
|
class CollectionIterator {
|
||||||
friend class CollectionData;
|
friend class CollectionData;
|
||||||
|
@ -10,7 +10,7 @@
|
|||||||
|
|
||||||
ARDUINOJSON_BEGIN_PRIVATE_NAMESPACE
|
ARDUINOJSON_BEGIN_PRIVATE_NAMESPACE
|
||||||
|
|
||||||
union VariantSlot;
|
class VariantData;
|
||||||
using SlotId = uint_t<ARDUINOJSON_SLOT_ID_SIZE * 8>;
|
using SlotId = uint_t<ARDUINOJSON_SLOT_ID_SIZE * 8>;
|
||||||
using SlotCount = SlotId;
|
using SlotCount = SlotId;
|
||||||
const SlotId NULL_SLOT = SlotId(-1);
|
const SlotId NULL_SLOT = SlotId(-1);
|
||||||
@ -18,7 +18,7 @@ const SlotId NULL_SLOT = SlotId(-1);
|
|||||||
class SlotWithId {
|
class SlotWithId {
|
||||||
public:
|
public:
|
||||||
SlotWithId() : slot_(nullptr), id_(NULL_SLOT) {}
|
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));
|
ARDUINOJSON_ASSERT((slot == nullptr) == (id == NULL_SLOT));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -30,17 +30,17 @@ class SlotWithId {
|
|||||||
return id_;
|
return id_;
|
||||||
}
|
}
|
||||||
|
|
||||||
VariantSlot* slot() const {
|
VariantData* slot() const {
|
||||||
return slot_;
|
return slot_;
|
||||||
}
|
}
|
||||||
|
|
||||||
VariantSlot* operator->() {
|
VariantData* operator->() {
|
||||||
ARDUINOJSON_ASSERT(slot_ != nullptr);
|
ARDUINOJSON_ASSERT(slot_ != nullptr);
|
||||||
return slot_;
|
return slot_;
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
VariantSlot* slot_;
|
VariantData* slot_;
|
||||||
SlotId id_;
|
SlotId id_;
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -50,7 +50,7 @@ class MemoryPool {
|
|||||||
void destroy(Allocator* allocator);
|
void destroy(Allocator* allocator);
|
||||||
|
|
||||||
SlotWithId allocSlot();
|
SlotWithId allocSlot();
|
||||||
VariantSlot* getSlot(SlotId id) const;
|
VariantData* getSlot(SlotId id) const;
|
||||||
void clear();
|
void clear();
|
||||||
void shrinkToFit(Allocator*);
|
void shrinkToFit(Allocator*);
|
||||||
SlotCount usage() const;
|
SlotCount usage() const;
|
||||||
@ -61,7 +61,7 @@ class MemoryPool {
|
|||||||
private:
|
private:
|
||||||
SlotCount capacity_;
|
SlotCount capacity_;
|
||||||
SlotCount usage_;
|
SlotCount usage_;
|
||||||
VariantSlot* slots_;
|
VariantData* slots_;
|
||||||
};
|
};
|
||||||
|
|
||||||
ARDUINOJSON_END_PRIVATE_NAMESPACE
|
ARDUINOJSON_END_PRIVATE_NAMESPACE
|
||||||
|
@ -5,14 +5,14 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <ArduinoJson/Memory/MemoryPool.hpp>
|
#include <ArduinoJson/Memory/MemoryPool.hpp>
|
||||||
#include <ArduinoJson/Variant/VariantSlot.hpp>
|
#include <ArduinoJson/Variant/VariantData.hpp>
|
||||||
|
|
||||||
ARDUINOJSON_BEGIN_PRIVATE_NAMESPACE
|
ARDUINOJSON_BEGIN_PRIVATE_NAMESPACE
|
||||||
|
|
||||||
inline void MemoryPool::create(SlotCount cap, Allocator* allocator) {
|
inline void MemoryPool::create(SlotCount cap, Allocator* allocator) {
|
||||||
ARDUINOJSON_ASSERT(cap > 0);
|
ARDUINOJSON_ASSERT(cap > 0);
|
||||||
slots_ =
|
slots_ =
|
||||||
reinterpret_cast<VariantSlot*>(allocator->allocate(slotsToBytes(cap)));
|
reinterpret_cast<VariantData*>(allocator->allocate(slotsToBytes(cap)));
|
||||||
capacity_ = slots_ ? cap : 0;
|
capacity_ = slots_ ? cap : 0;
|
||||||
usage_ = 0;
|
usage_ = 0;
|
||||||
}
|
}
|
||||||
@ -26,7 +26,7 @@ inline void MemoryPool::destroy(Allocator* allocator) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
inline void MemoryPool::shrinkToFit(Allocator* allocator) {
|
inline void MemoryPool::shrinkToFit(Allocator* allocator) {
|
||||||
auto newSlots = reinterpret_cast<VariantSlot*>(
|
auto newSlots = reinterpret_cast<VariantData*>(
|
||||||
allocator->reallocate(slots_, slotsToBytes(usage_)));
|
allocator->reallocate(slots_, slotsToBytes(usage_)));
|
||||||
if (newSlots) {
|
if (newSlots) {
|
||||||
slots_ = newSlots;
|
slots_ = newSlots;
|
||||||
@ -44,7 +44,7 @@ inline SlotWithId MemoryPool::allocSlot() {
|
|||||||
return {slot, SlotId(index)};
|
return {slot, SlotId(index)};
|
||||||
}
|
}
|
||||||
|
|
||||||
inline VariantSlot* MemoryPool::getSlot(SlotId id) const {
|
inline VariantData* MemoryPool::getSlot(SlotId id) const {
|
||||||
ARDUINOJSON_ASSERT(id < usage_);
|
ARDUINOJSON_ASSERT(id < usage_);
|
||||||
return &slots_[id];
|
return &slots_[id];
|
||||||
}
|
}
|
||||||
@ -58,11 +58,11 @@ inline void MemoryPool::clear() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
inline SlotCount MemoryPool::bytesToSlots(size_t n) {
|
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) {
|
inline size_t MemoryPool::slotsToBytes(SlotCount n) {
|
||||||
return n * sizeof(VariantSlot);
|
return n * sizeof(VariantData);
|
||||||
}
|
}
|
||||||
|
|
||||||
inline SlotWithId MemoryPoolList::allocFromFreeList() {
|
inline SlotWithId MemoryPoolList::allocFromFreeList() {
|
||||||
|
@ -97,7 +97,7 @@ class MemoryPoolList {
|
|||||||
|
|
||||||
void freeSlot(SlotWithId slot);
|
void freeSlot(SlotWithId slot);
|
||||||
|
|
||||||
VariantSlot* getSlot(SlotId id) const {
|
VariantData* getSlot(SlotId id) const {
|
||||||
if (id == NULL_SLOT)
|
if (id == NULL_SLOT)
|
||||||
return nullptr;
|
return nullptr;
|
||||||
auto poolIndex = SlotId(id / ARDUINOJSON_POOL_CAPACITY);
|
auto poolIndex = SlotId(id / ARDUINOJSON_POOL_CAPACITY);
|
||||||
|
@ -13,7 +13,6 @@
|
|||||||
|
|
||||||
ARDUINOJSON_BEGIN_PRIVATE_NAMESPACE
|
ARDUINOJSON_BEGIN_PRIVATE_NAMESPACE
|
||||||
|
|
||||||
union VariantSlot;
|
|
||||||
class MemoryPool;
|
class MemoryPool;
|
||||||
class VariantData;
|
class VariantData;
|
||||||
class VariantWithId;
|
class VariantWithId;
|
||||||
|
@ -7,7 +7,6 @@
|
|||||||
#include <ArduinoJson/Collection/CollectionData.hpp>
|
#include <ArduinoJson/Collection/CollectionData.hpp>
|
||||||
#include <ArduinoJson/Memory/ResourceManager.hpp>
|
#include <ArduinoJson/Memory/ResourceManager.hpp>
|
||||||
#include <ArduinoJson/Variant/VariantData.hpp>
|
#include <ArduinoJson/Variant/VariantData.hpp>
|
||||||
#include <ArduinoJson/Variant/VariantSlot.hpp>
|
|
||||||
|
|
||||||
ARDUINOJSON_BEGIN_PRIVATE_NAMESPACE
|
ARDUINOJSON_BEGIN_PRIVATE_NAMESPACE
|
||||||
|
|
||||||
@ -17,7 +16,7 @@ inline VariantWithId ResourceManager::allocVariant() {
|
|||||||
overflowed_ = true;
|
overflowed_ = true;
|
||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
return {new (&p->variant) VariantData, p.id()};
|
return {new (p.slot()) VariantData, p.id()};
|
||||||
}
|
}
|
||||||
|
|
||||||
inline void ResourceManager::freeVariant(VariantWithId variant) {
|
inline void ResourceManager::freeVariant(VariantWithId variant) {
|
||||||
|
@ -12,7 +12,6 @@
|
|||||||
|
|
||||||
ARDUINOJSON_BEGIN_PRIVATE_NAMESPACE
|
ARDUINOJSON_BEGIN_PRIVATE_NAMESPACE
|
||||||
|
|
||||||
union VariantSlot;
|
|
||||||
class MemoryPool;
|
class MemoryPool;
|
||||||
|
|
||||||
class StringPool {
|
class StringPool {
|
||||||
|
@ -6,7 +6,7 @@
|
|||||||
|
|
||||||
#include <ArduinoJson/Object/ObjectData.hpp>
|
#include <ArduinoJson/Object/ObjectData.hpp>
|
||||||
#include <ArduinoJson/Variant/VariantCompare.hpp>
|
#include <ArduinoJson/Variant/VariantCompare.hpp>
|
||||||
#include <ArduinoJson/Variant/VariantSlot.hpp>
|
#include <ArduinoJson/Variant/VariantData.hpp>
|
||||||
|
|
||||||
ARDUINOJSON_BEGIN_PRIVATE_NAMESPACE
|
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.
|
// Returns the size (in bytes) of an object with n members.
|
||||||
constexpr size_t sizeofObject(size_t n) {
|
constexpr size_t sizeofObject(size_t n) {
|
||||||
return 2 * n * sizeof(VariantSlot);
|
return 2 * n * sizeof(VariantData);
|
||||||
}
|
}
|
||||||
|
|
||||||
ARDUINOJSON_END_PRIVATE_NAMESPACE
|
ARDUINOJSON_END_PRIVATE_NAMESPACE
|
||||||
|
@ -538,7 +538,7 @@ class VariantWithId : public SlotWithId {
|
|||||||
public:
|
public:
|
||||||
VariantWithId() {}
|
VariantWithId() {}
|
||||||
VariantWithId(VariantData* data, SlotId id)
|
VariantWithId(VariantData* data, SlotId id)
|
||||||
: SlotWithId(reinterpret_cast<VariantSlot*>(data), id) {}
|
: SlotWithId(reinterpret_cast<VariantData*>(data), id) {}
|
||||||
|
|
||||||
VariantData* data() {
|
VariantData* data() {
|
||||||
return reinterpret_cast<VariantData*>(slot());
|
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