Skip to content

Commit 0021ec8

Browse files
committed
StringPool: change dereference to take a StringNode*
1 parent 372f2f2 commit 0021ec8

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
@@ -134,8 +134,8 @@ class ResourceManager {
134134
StringNode::destroy(node, allocator_);
135135
}
136136

137-
void dereferenceString(const char* s) {
138-
stringPool_.dereference(s, allocator_);
137+
void dereferenceString(StringNode* node) {
138+
stringPool_.dereference(node, allocator_);
139139
}
140140

141141
SlotId saveStaticString(const char* s) {

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
@@ -531,7 +531,7 @@ class VariantImpl {
531531
return;
532532

533533
if (data_->type & VariantTypeBits::OwnedStringBit)
534-
resources_->dereferenceString(data_->content.asOwnedString->data);
534+
resources_->dereferenceString(asOwnedString());
535535

536536
#if ARDUINOJSON_USE_8_BYTE_POOL
537537
if (data_->type & VariantTypeBits::EightByteBit)

0 commit comments

Comments
 (0)