Skip to content

Commit c2e756d

Browse files
committed
ResourceManagerTests pass
1 parent 94aacf8 commit c2e756d

File tree

6 files changed

+25
-24
lines changed

6 files changed

+25
-24
lines changed

src/ArduinoJson/Configuration.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -274,9 +274,9 @@
274274
#endif
275275

276276
#if ARDUINOJSON_USE_LONG_LONG || ARDUINOJSON_USE_DOUBLE
277-
# define ARDUINOJSON_USE_8_BYTE_VALUES 1
277+
# define ARDUINOJSON_USE_8_BYTE_POOL 1
278278
#else
279-
# define ARDUINOJSON_USE_8_BYTE_VALUES 0
279+
# define ARDUINOJSON_USE_8_BYTE_POOL 0
280280
#endif
281281

282282
#if defined(nullptr)

src/ArduinoJson/Memory/ResourceManager.hpp

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ class ResourceManager {
3939
swap(a.stringPool_, b.stringPool_);
4040
swap(a.variantPools_, b.variantPools_);
4141
swap(a.staticStringsPools_, b.staticStringsPools_);
42-
swap(a.lgValuePools_, b.lgValuePools_);
42+
swap(a.eightBytePools_, b.eightBytePools_);
4343
swap_(a.allocator_, b.allocator_);
4444
swap_(a.overflowed_, b.overflowed_);
4545
}
@@ -60,7 +60,7 @@ class ResourceManager {
6060
void freeVariant(Slot<VariantData> slot);
6161
VariantData* getVariant(SlotId id) const;
6262

63-
#if ARDUINOJSON_USE_8_BYTE_VALUES
63+
#if ARDUINOJSON_USE_8_BYTE_POOL
6464
Slot<EightByteValue> allocEightByte();
6565
void freeEightByte(SlotId slot);
6666
EightByteValue* getEightByte(SlotId id) const;
@@ -132,16 +132,16 @@ class ResourceManager {
132132
variantPools_.clear(allocator_);
133133
stringPool_.clear(allocator_);
134134
staticStringsPools_.clear(allocator_);
135-
#if ARDUINOJSON_USE_8_BYTE_VALUES
136-
lgValuePools_.clear(allocator_);
135+
#if ARDUINOJSON_USE_8_BYTE_POOL
136+
eightBytePools_.clear(allocator_);
137137
#endif
138138
}
139139

140140
void shrinkToFit() {
141141
variantPools_.shrinkToFit(allocator_);
142142
staticStringsPools_.shrinkToFit(allocator_);
143-
#if ARDUINOJSON_USE_8_BYTE_VALUES
144-
lgValuePools_.shrinkToFit(allocator_);
143+
#if ARDUINOJSON_USE_8_BYTE_POOL
144+
eightBytePools_.shrinkToFit(allocator_);
145145
#endif
146146
}
147147

@@ -151,7 +151,7 @@ class ResourceManager {
151151
StringPool stringPool_;
152152
MemoryPoolList<SlotData> variantPools_;
153153
MemoryPoolList<const char*> staticStringsPools_;
154-
#if ARDUINOJSON_USE_8_BYTE_VALUES
154+
#if ARDUINOJSON_USE_8_BYTE_POOL
155155
MemoryPoolList<EightByteValue> eightBytePools_;
156156
#endif
157157
};

src/ArduinoJson/Memory/ResourceManagerImpl.hpp

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,13 @@
1212
ARDUINOJSON_BEGIN_PRIVATE_NAMESPACE
1313

1414
inline Slot<VariantData> ResourceManager::allocVariant() {
15-
auto p = variantPools_.allocSlot(allocator_);
16-
if (!p) {
15+
auto slot = variantPools_.allocSlot(allocator_);
16+
if (!slot) {
1717
overflowed_ = true;
1818
return {};
1919
}
20-
return {new (&p->variant) VariantData, p.id()};
20+
new (slot.ptr()) VariantData();
21+
return slot;
2122
}
2223

2324
inline void ResourceManager::freeVariant(Slot<VariantData> variant) {
@@ -29,7 +30,7 @@ inline VariantData* ResourceManager::getVariant(SlotId id) const {
2930
return reinterpret_cast<VariantData*>(variantPools_.getSlot(id));
3031
}
3132

32-
#if ARDUINOJSON_USE_8_BYTE_VALUES
33+
#if ARDUINOJSON_USE_8_BYTE_POOL
3334
inline Slot<EightByteValue> ResourceManager::allocEightByte() {
3435
auto slot = eightBytePools_.allocSlot(allocator_);
3536
if (!slot) {
@@ -45,7 +46,7 @@ inline void ResourceManager::freeEightByte(SlotId id) {
4546
}
4647

4748
inline EightByteValue* ResourceManager::getEightByte(SlotId id) const {
48-
return eightBytePools_.getSlot(id).ptr();
49+
return eightBytePools_.getSlot(id);
4950
}
5051
#endif
5152

src/ArduinoJson/Variant/VariantContent.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ union VariantContent {
6262
char asTinyString[tinyStringMaxLength + 1];
6363
};
6464

65-
#if ARDUINOJSON_USE_8_BYTE_VALUES
65+
#if ARDUINOJSON_USE_8_BYTE_POOL
6666
union EightByteValue {
6767
# if ARDUINOJSON_USE_LONG_LONG
6868
uint64_t asUint64;

src/ArduinoJson/Variant/VariantData.hpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ class VariantData {
5353
template <typename TVisitor>
5454
typename TVisitor::result_type accept(
5555
TVisitor& visit, const ResourceManager* resources) const {
56-
#if ARDUINOJSON_USE_EIGHT_BYTE_VALUES
56+
#if ARDUINOJSON_USE_8_BYTE_POOL
5757
auto eightByteValue = getEightByte(resources);
5858
#else
5959
(void)resources; // silence warning
@@ -145,7 +145,7 @@ class VariantData {
145145
}
146146

147147
bool asBoolean(const ResourceManager* resources) const {
148-
#if ARDUINOJSON_USE_EIGHT_BYTE_VALUES
148+
#if ARDUINOJSON_USE_8_BYTE_POOL
149149
auto eightByteValue = getEightByte(resources);
150150
#else
151151
(void)resources; // silence warning
@@ -193,7 +193,7 @@ class VariantData {
193193
template <typename T>
194194
T asFloat(const ResourceManager* resources) const {
195195
static_assert(is_floating_point<T>::value, "T must be a floating point");
196-
#if ARDUINOJSON_USE_EIGHT_BYTE_VALUES
196+
#if ARDUINOJSON_USE_8_BYTE_POOL
197197
auto eightByteValue = getEightByte(resources);
198198
#else
199199
(void)resources; // silence warning
@@ -238,7 +238,7 @@ class VariantData {
238238
template <typename T>
239239
T asIntegral(const ResourceManager* resources) const {
240240
static_assert(is_integral<T>::value, "T must be an integral type");
241-
#if ARDUINOJSON_USE_EIGHT_BYTE_VALUES
241+
#if ARDUINOJSON_USE_8_BYTE_POOL
242242
auto eightByteValue = getEightByte(resources);
243243
#else
244244
(void)resources; // silence warning
@@ -314,7 +314,7 @@ class VariantData {
314314
}
315315
}
316316

317-
#if ARDUINOJSON_USE_8_BYTE_VALUES
317+
#if ARDUINOJSON_USE_8_BYTE_POOL
318318
const EightByteValue* getEightByte(const ResourceManager* resources) const;
319319
#endif
320320

src/ArduinoJson/Variant/VariantImpl.hpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ inline void VariantData::clear(ResourceManager* resources) {
6161
if (type_ & VariantTypeBits::OwnedStringBit)
6262
resources->dereferenceString(content_.asOwnedString->data);
6363

64-
#if ARDUINOJSON_USE_EIGHT_BYTE_VALUES
64+
#if ARDUINOJSON_USE_8_BYTE_POOL
6565
if (type_ & VariantTypeBits::EightByteBit)
6666
resources->freeEightByte(content_.asSlotId);
6767
#endif
@@ -73,11 +73,11 @@ inline void VariantData::clear(ResourceManager* resources) {
7373
type_ = VariantType::Null;
7474
}
7575

76-
#if ARDUINOJSON_USE_EIGHT_BYTE_VALUES
77-
inline const EightByteValue* VariantData::getEightByteValue(
76+
#if ARDUINOJSON_USE_8_BYTE_POOL
77+
inline const EightByteValue* VariantData::getEightByte(
7878
const ResourceManager* resources) const {
7979
return type_ & VariantTypeBits::EightByteBit
80-
? resources->getEightByteValue(content_.asSlotId)
80+
? resources->getEightByte(content_.asSlotId)
8181
: 0;
8282
}
8383
#endif

0 commit comments

Comments
 (0)