Skip to content

Commit a1aeec0

Browse files
committed
StringPool: change dereference to take a StringNode*
1 parent 8a9a91a commit a1aeec0

File tree

3 files changed

+11
-11
lines changed

3 files changed

+11
-11
lines changed

src/ArduinoJson/Memory/ResourceManager.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -132,8 +132,8 @@ class ResourceManager {
132132
StringNode::destroy(node, allocator_);
133133
}
134134

135-
void dereferenceString(const char* s) {
136-
stringPool_.dereference(s, allocator_);
135+
void dereferenceString(StringNode* node) {
136+
stringPool_.dereference(node, allocator_);
137137
}
138138

139139
void clear() {

src/ArduinoJson/Memory/StringPool.hpp

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -78,20 +78,20 @@ class StringPool {
7878
return nullptr;
7979
}
8080

81-
void dereference(const char* s, Allocator* allocator) {
81+
void dereference(StringNode* nodeToRemove, Allocator* allocator) {
8282
StringNode* prev = nullptr;
83-
for (auto node = strings_; node; node = node->next) {
84-
if (node->data == s) {
85-
if (--node->references == 0) {
83+
for (auto current = strings_; current; current = current->next) {
84+
if (current == nodeToRemove) {
85+
if (--current->references == 0) {
8686
if (prev)
87-
prev->next = node->next;
87+
prev->next = current->next;
8888
else
89-
strings_ = node->next;
90-
StringNode::destroy(node, allocator);
89+
strings_ = current->next;
90+
StringNode::destroy(current, allocator);
9191
}
9292
return;
9393
}
94-
prev = node;
94+
prev = current;
9595
}
9696
}
9797

src/ArduinoJson/Variant/VariantImpl.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -499,7 +499,7 @@ class VariantImpl {
499499
return;
500500

501501
if (data_->type & VariantTypeBits::OwnedStringBit)
502-
resources_->dereferenceString(data_->content.asStringNode->data);
502+
resources_->dereferenceString(asStringNode());
503503

504504
#if ARDUINOJSON_USE_8_BYTE_POOL
505505
if (data_->type & VariantTypeBits::EightByteBit)

0 commit comments

Comments
 (0)