mirror of
https://github.com/bblanchon/ArduinoJson.git
synced 2025-07-29 10:17:39 +02:00
StringPool: change dereference
to take a StringNode*
This commit is contained in:
@ -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) {
|
||||
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -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)
|
||||
|
Reference in New Issue
Block a user