Skip to content

Commit

Permalink
Replace sizeof(VariantData) with sizeof(SlotData)
Browse files Browse the repository at this point in the history
  • Loading branch information
bblanchon committed Sep 10, 2024
1 parent d92eee8 commit a1809d0
Show file tree
Hide file tree
Showing 8 changed files with 11 additions and 12 deletions.
3 changes: 1 addition & 2 deletions extras/conf_test/avr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,7 @@ static_assert(ARDUINOJSON_LITTLE_ENDIAN == 1, "ARDUINOJSON_LITTLE_ENDIAN");

static_assert(ARDUINOJSON_USE_DOUBLE == 0, "ARDUINOJSON_USE_DOUBLE");

static_assert(sizeof(ArduinoJson::detail::VariantData) == 6,
"sizeof(VariantData)");
static_assert(ArduinoJson::detail::ResourceManager::slotSize == 6, "slot size");

void setup() {}
void loop() {}
3 changes: 1 addition & 2 deletions extras/conf_test/esp8266.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +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::VariantData) == 8,
"sizeof(VariantData)");
static_assert(ArduinoJson::detail::ResourceManager::slotSize == 8, "slot size");

void setup() {}
void loop() {}
4 changes: 2 additions & 2 deletions extras/conf_test/x64.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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::VariantData) == 16,
"sizeof(VariantData)");
static_assert(ArduinoJson::detail::ResourceManager::slotSize == 16,
"slot size");

int main() {}
3 changes: 1 addition & 2 deletions extras/conf_test/x86.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ static_assert(ARDUINOJSON_LITTLE_ENDIAN == 1, "ARDUINOJSON_LITTLE_ENDIAN");

static_assert(ARDUINOJSON_USE_DOUBLE == 1, "ARDUINOJSON_USE_DOUBLE");

static_assert(sizeof(ArduinoJson::detail::VariantData) == 8,
"sizeof(VariantData)");
static_assert(ArduinoJson::detail::ResourceManager::slotSize == 8, "slot size");

int main() {}
4 changes: 2 additions & 2 deletions extras/tests/ResourceManager/shrinkToFit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ TEST_CASE("ResourceManager::shrinkToFit()") {
REQUIRE(spyingAllocator.log() ==
AllocatorLog{
Allocate(sizeofPool()),
Reallocate(sizeofPool(), sizeof(VariantData)),
Reallocate(sizeofPool(), sizeofPool(1)),
});
}

Expand All @@ -49,7 +49,7 @@ TEST_CASE("ResourceManager::shrinkToFit()") {

REQUIRE(spyingAllocator.log() ==
AllocatorLog{
Reallocate(sizeofPool(), sizeof(VariantData)),
Reallocate(sizeofPool(), sizeofPool(1)),
Reallocate(sizeofPoolList(ARDUINOJSON_INITIAL_POOL_COUNT * 2),
sizeofPoolList(ARDUINOJSON_INITIAL_POOL_COUNT + 1)),
});
Expand Down
2 changes: 1 addition & 1 deletion src/ArduinoJson/Array/ArrayImpl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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(VariantData);
return n * ResourceManager::slotSize;
}

ARDUINOJSON_END_PRIVATE_NAMESPACE
2 changes: 2 additions & 0 deletions src/ArduinoJson/Memory/ResourceManager.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ class ResourceManager {
};

public:
constexpr static size_t slotSize = sizeof(SlotData);

ResourceManager(Allocator* allocator = DefaultAllocator::instance())
: allocator_(allocator), overflowed_(false) {}

Expand Down
2 changes: 1 addition & 1 deletion src/ArduinoJson/Object/ObjectImpl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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(VariantData);
return 2 * n * ResourceManager::slotSize;
}

ARDUINOJSON_END_PRIVATE_NAMESPACE

0 comments on commit a1809d0

Please sign in to comment.