Skip to content

Commit 88769c4

Browse files
committed
ResourceManager: decouple from VariantImpl
1 parent 01de2f3 commit 88769c4

File tree

5 files changed

+10
-7
lines changed

5 files changed

+10
-7
lines changed

src/ArduinoJson/Array/ArrayImpl.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ inline bool VariantImpl::addValue(const T& value, VariantData* data,
7070
return false;
7171
JsonVariant variant(slot.ptr(), resources);
7272
if (!variant.set(value)) {
73-
resources->freeVariant(slot);
73+
freeVariant(slot, resources);
7474
return false;
7575
}
7676
appendOne(slot, data, resources);

src/ArduinoJson/Collection/CollectionImpl.hpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ inline void VariantImpl::empty(VariantData* data, ResourceManager* resources) {
7474
auto currId = next;
7575
auto slot = resources->getVariant(next);
7676
next = slot->next;
77-
resources->freeVariant({slot, currId});
77+
freeVariant({slot, currId}, resources);
7878
}
7979

8080
coll->head = NULL_SLOT;
@@ -112,7 +112,7 @@ inline void VariantImpl::removeOne(iterator it) {
112112
coll->head = next;
113113
if (next == NULL_SLOT)
114114
coll->tail = prev.id();
115-
resources_->freeVariant({it.slot_, it.currentId_});
115+
freeVariant({it.slot_, it.currentId_}, resources_);
116116
}
117117

118118
inline void VariantImpl::removePair(iterator it) {
@@ -126,7 +126,7 @@ inline void VariantImpl::removePair(iterator it) {
126126

127127
// remove value slot
128128
keySlot->next = valueSlot->next;
129-
resources_->freeVariant({valueSlot, valueId});
129+
freeVariant({valueSlot, valueId}, resources_);
130130

131131
// remove key slot
132132
removeOne(it);

src/ArduinoJson/Memory/ResourceManager.hpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414

1515
ARDUINOJSON_BEGIN_PRIVATE_NAMESPACE
1616

17-
struct VariantData;
1817
class VariantWithId;
1918

2019
class ResourceManager {

src/ArduinoJson/Memory/ResourceManagerImpl.hpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66

77
#include <ArduinoJson/Memory/ResourceManager.hpp>
88
#include <ArduinoJson/Polyfills/alias_cast.hpp>
9-
#include <ArduinoJson/Variant/VariantImpl.hpp>
109

1110
ARDUINOJSON_BEGIN_PRIVATE_NAMESPACE
1211

@@ -21,7 +20,7 @@ inline Slot<VariantData> ResourceManager::allocVariant() {
2120
}
2221

2322
inline void ResourceManager::freeVariant(Slot<VariantData> slot) {
24-
VariantImpl::clear(slot.ptr(), this);
23+
ARDUINOJSON_ASSERT(slot->type == VariantType::Null); // must be cleared first
2524
variantPools_.freeSlot(slot);
2625
}
2726

src/ArduinoJson/Variant/VariantImpl.hpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -635,6 +635,11 @@ class VariantImpl {
635635
void removeOne(iterator it);
636636
void removePair(iterator it);
637637

638+
static void freeVariant(Slot<VariantData> slot, ResourceManager* resources) {
639+
clear(slot.ptr(), resources);
640+
resources->freeVariant(slot);
641+
}
642+
638643
Slot<VariantData> getPreviousSlot(VariantData*) const;
639644
};
640645

0 commit comments

Comments
 (0)