From 0021ec81d1e7efb193668ed5725b3c929c71d8c6 Mon Sep 17 00:00:00 2001 From: Benoit Blanchon Date: Wed, 16 Jul 2025 12:32:35 +0200 Subject: [PATCH] StringPool: change `dereference` to take a `StringNode*` --- src/ArduinoJson/Memory/ResourceManager.hpp | 4 ++-- src/ArduinoJson/Memory/StringPool.hpp | 16 ++++++++-------- src/ArduinoJson/Variant/VariantImpl.hpp | 2 +- 3 files changed, 11 insertions(+), 11 deletions(-) diff --git a/src/ArduinoJson/Memory/ResourceManager.hpp b/src/ArduinoJson/Memory/ResourceManager.hpp index d99f07f6..ceacfb5c 100644 --- a/src/ArduinoJson/Memory/ResourceManager.hpp +++ b/src/ArduinoJson/Memory/ResourceManager.hpp @@ -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) { diff --git a/src/ArduinoJson/Memory/StringPool.hpp b/src/ArduinoJson/Memory/StringPool.hpp index 0b71ed22..22e9d8cd 100644 --- a/src/ArduinoJson/Memory/StringPool.hpp +++ b/src/ArduinoJson/Memory/StringPool.hpp @@ -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; } } diff --git a/src/ArduinoJson/Variant/VariantImpl.hpp b/src/ArduinoJson/Variant/VariantImpl.hpp index 47756f2b..f89c933f 100644 --- a/src/ArduinoJson/Variant/VariantImpl.hpp +++ b/src/ArduinoJson/Variant/VariantImpl.hpp @@ -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)