StringPool: change dereference to take a StringNode*

This commit is contained in:
Benoit Blanchon
2025-07-16 12:32:35 +02:00
parent 372f2f2767
commit 0021ec81d1
3 changed files with 11 additions and 11 deletions

View File

@ -134,8 +134,8 @@ class ResourceManager {
StringNode::destroy(node, allocator_); StringNode::destroy(node, allocator_);
} }
void dereferenceString(const char* s) { void dereferenceString(StringNode* node) {
stringPool_.dereference(s, allocator_); stringPool_.dereference(node, allocator_);
} }
SlotId saveStaticString(const char* s) { SlotId saveStaticString(const char* s) {

View File

@ -78,20 +78,20 @@ class StringPool {
return nullptr; return nullptr;
} }
void dereference(const char* s, Allocator* allocator) { void dereference(StringNode* nodeToRemove, Allocator* allocator) {
StringNode* prev = nullptr; StringNode* prev = nullptr;
for (auto node = strings_; node; node = node->next) { for (auto current = strings_; current; current = current->next) {
if (node->data == s) { if (current == nodeToRemove) {
if (--node->references == 0) { if (--current->references == 0) {
if (prev) if (prev)
prev->next = node->next; prev->next = current->next;
else else
strings_ = node->next; strings_ = current->next;
StringNode::destroy(node, allocator); StringNode::destroy(current, allocator);
} }
return; return;
} }
prev = node; prev = current;
} }
} }

View File

@ -531,7 +531,7 @@ class VariantImpl {
return; return;
if (data_->type & VariantTypeBits::OwnedStringBit) if (data_->type & VariantTypeBits::OwnedStringBit)
resources_->dereferenceString(data_->content.asOwnedString->data); resources_->dereferenceString(asOwnedString());
#if ARDUINOJSON_USE_8_BYTE_POOL #if ARDUINOJSON_USE_8_BYTE_POOL
if (data_->type & VariantTypeBits::EightByteBit) if (data_->type & VariantTypeBits::EightByteBit)