Skip to content

Commit a1809d0

Browse files
committed
Replace sizeof(VariantData) with sizeof(SlotData)
1 parent d92eee8 commit a1809d0

File tree

8 files changed

+11
-12
lines changed

8 files changed

+11
-12
lines changed

extras/conf_test/avr.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,7 @@ static_assert(ARDUINOJSON_LITTLE_ENDIAN == 1, "ARDUINOJSON_LITTLE_ENDIAN");
1010

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

13-
static_assert(sizeof(ArduinoJson::detail::VariantData) == 6,
14-
"sizeof(VariantData)");
13+
static_assert(ArduinoJson::detail::ResourceManager::slotSize == 6, "slot size");
1514

1615
void setup() {}
1716
void loop() {}

extras/conf_test/esp8266.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,7 @@ static_assert(ARDUINOJSON_LITTLE_ENDIAN == 1, "ARDUINOJSON_LITTLE_ENDIAN");
88

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

11-
static_assert(sizeof(ArduinoJson::detail::VariantData) == 8,
12-
"sizeof(VariantData)");
11+
static_assert(ArduinoJson::detail::ResourceManager::slotSize == 8, "slot size");
1312

1413
void setup() {}
1514
void loop() {}

extras/conf_test/x64.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ static_assert(ARDUINOJSON_LITTLE_ENDIAN == 1, "ARDUINOJSON_LITTLE_ENDIAN");
88

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

11-
static_assert(sizeof(ArduinoJson::detail::VariantData) == 16,
12-
"sizeof(VariantData)");
11+
static_assert(ArduinoJson::detail::ResourceManager::slotSize == 16,
12+
"slot size");
1313

1414
int main() {}

extras/conf_test/x86.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ static_assert(ARDUINOJSON_LITTLE_ENDIAN == 1, "ARDUINOJSON_LITTLE_ENDIAN");
88

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

11-
static_assert(sizeof(ArduinoJson::detail::VariantData) == 8,
12-
"sizeof(VariantData)");
11+
static_assert(ArduinoJson::detail::ResourceManager::slotSize == 8, "slot size");
1312

1413
int main() {}

extras/tests/ResourceManager/shrinkToFit.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ TEST_CASE("ResourceManager::shrinkToFit()") {
2828
REQUIRE(spyingAllocator.log() ==
2929
AllocatorLog{
3030
Allocate(sizeofPool()),
31-
Reallocate(sizeofPool(), sizeof(VariantData)),
31+
Reallocate(sizeofPool(), sizeofPool(1)),
3232
});
3333
}
3434

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

5050
REQUIRE(spyingAllocator.log() ==
5151
AllocatorLog{
52-
Reallocate(sizeofPool(), sizeof(VariantData)),
52+
Reallocate(sizeofPool(), sizeofPool(1)),
5353
Reallocate(sizeofPoolList(ARDUINOJSON_INITIAL_POOL_COUNT * 2),
5454
sizeofPoolList(ARDUINOJSON_INITIAL_POOL_COUNT + 1)),
5555
});

src/ArduinoJson/Array/ArrayImpl.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ inline bool ArrayData::addValue(T&& value, ResourceManager* resources) {
7373

7474
// Returns the size (in bytes) of an array with n elements.
7575
constexpr size_t sizeofArray(size_t n) {
76-
return n * sizeof(VariantData);
76+
return n * ResourceManager::slotSize;
7777
}
7878

7979
ARDUINOJSON_END_PRIVATE_NAMESPACE

src/ArduinoJson/Memory/ResourceManager.hpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@ class ResourceManager {
2626
};
2727

2828
public:
29+
constexpr static size_t slotSize = sizeof(SlotData);
30+
2931
ResourceManager(Allocator* allocator = DefaultAllocator::instance())
3032
: allocator_(allocator), overflowed_(false) {}
3133

src/ArduinoJson/Object/ObjectImpl.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ inline VariantData* ObjectData::addMember(TAdaptedString key,
7070

7171
// Returns the size (in bytes) of an object with n members.
7272
constexpr size_t sizeofObject(size_t n) {
73-
return 2 * n * sizeof(VariantData);
73+
return 2 * n * ResourceManager::slotSize;
7474
}
7575

7676
ARDUINOJSON_END_PRIVATE_NAMESPACE

0 commit comments

Comments
 (0)