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_);
}
void dereferenceString(const char* s) {
stringPool_.dereference(s, allocator_);
void dereferenceString(StringNode* node) {
stringPool_.dereference(node, allocator_);
}
SlotId saveStaticString(const char* s) {

View File

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

View File

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