mirror of
https://github.com/bblanchon/ArduinoJson.git
synced 2025-07-21 22:42:25 +02:00
Move CollectionData::releaseSlot()
to ResourceManager::freeSlot()
This commit is contained in:
@ -2,9 +2,7 @@
|
|||||||
// Copyright © 2014-2024, Benoit BLANCHON
|
// Copyright © 2014-2024, Benoit BLANCHON
|
||||||
// MIT License
|
// MIT License
|
||||||
|
|
||||||
#include <ArduinoJson/Memory/Alignment.hpp>
|
#include <ArduinoJson.hpp>
|
||||||
#include <ArduinoJson/Memory/ResourceManager.hpp>
|
|
||||||
#include <ArduinoJson/Memory/VariantPoolImpl.hpp>
|
|
||||||
#include <catch.hpp>
|
#include <catch.hpp>
|
||||||
|
|
||||||
#include "Allocators.hpp"
|
#include "Allocators.hpp"
|
||||||
|
@ -36,6 +36,7 @@
|
|||||||
#include "ArduinoJson/Array/ElementProxy.hpp"
|
#include "ArduinoJson/Array/ElementProxy.hpp"
|
||||||
#include "ArduinoJson/Array/Utilities.hpp"
|
#include "ArduinoJson/Array/Utilities.hpp"
|
||||||
#include "ArduinoJson/Collection/CollectionImpl.hpp"
|
#include "ArduinoJson/Collection/CollectionImpl.hpp"
|
||||||
|
#include "ArduinoJson/Memory/ResourceManagerImpl.hpp"
|
||||||
#include "ArduinoJson/Memory/VariantPoolImpl.hpp"
|
#include "ArduinoJson/Memory/VariantPoolImpl.hpp"
|
||||||
#include "ArduinoJson/Object/MemberProxy.hpp"
|
#include "ArduinoJson/Object/MemberProxy.hpp"
|
||||||
#include "ArduinoJson/Object/ObjectImpl.hpp"
|
#include "ArduinoJson/Object/ObjectImpl.hpp"
|
||||||
|
@ -116,7 +116,6 @@ class CollectionData {
|
|||||||
|
|
||||||
private:
|
private:
|
||||||
SlotWithId getPreviousSlot(VariantSlot*, const ResourceManager*) const;
|
SlotWithId getPreviousSlot(VariantSlot*, const ResourceManager*) const;
|
||||||
void releaseSlot(SlotWithId, ResourceManager*);
|
|
||||||
};
|
};
|
||||||
|
|
||||||
inline const VariantData* collectionToVariant(
|
inline const VariantData* collectionToVariant(
|
||||||
|
@ -69,7 +69,7 @@ inline void CollectionData::clear(ResourceManager* resources) {
|
|||||||
auto currId = next;
|
auto currId = next;
|
||||||
auto slot = resources->getSlot(next);
|
auto slot = resources->getSlot(next);
|
||||||
next = slot->next();
|
next = slot->next();
|
||||||
releaseSlot(SlotWithId(slot, currId), resources);
|
resources->freeSlot(SlotWithId(slot, currId));
|
||||||
}
|
}
|
||||||
|
|
||||||
head_ = NULL_SLOT;
|
head_ = NULL_SLOT;
|
||||||
@ -102,7 +102,7 @@ inline void CollectionData::remove(iterator it, ResourceManager* resources) {
|
|||||||
head_ = next;
|
head_ = next;
|
||||||
if (next == NULL_SLOT)
|
if (next == NULL_SLOT)
|
||||||
tail_ = prev.id();
|
tail_ = prev.id();
|
||||||
releaseSlot({it.slot_, it.currentId_}, resources);
|
resources->freeSlot({it.slot_, it.currentId_});
|
||||||
}
|
}
|
||||||
|
|
||||||
inline size_t CollectionData::nesting(const ResourceManager* resources) const {
|
inline size_t CollectionData::nesting(const ResourceManager* resources) const {
|
||||||
@ -122,12 +122,4 @@ inline size_t CollectionData::size(const ResourceManager* resources) const {
|
|||||||
return count;
|
return count;
|
||||||
}
|
}
|
||||||
|
|
||||||
inline void CollectionData::releaseSlot(SlotWithId slot,
|
|
||||||
ResourceManager* resources) {
|
|
||||||
if (slot->ownsKey())
|
|
||||||
resources->dereferenceString(slot->key());
|
|
||||||
slot->data()->setNull(resources);
|
|
||||||
resources->freeSlot(slot);
|
|
||||||
}
|
|
||||||
|
|
||||||
ARDUINOJSON_END_PRIVATE_NAMESPACE
|
ARDUINOJSON_END_PRIVATE_NAMESPACE
|
||||||
|
@ -56,9 +56,7 @@ class ResourceManager {
|
|||||||
return p;
|
return p;
|
||||||
}
|
}
|
||||||
|
|
||||||
void freeSlot(SlotWithId id) {
|
void freeSlot(SlotWithId slot);
|
||||||
variantPools_.freeSlot(id);
|
|
||||||
}
|
|
||||||
|
|
||||||
VariantSlot* getSlot(SlotId id) const {
|
VariantSlot* getSlot(SlotId id) const {
|
||||||
return variantPools_.getSlot(id);
|
return variantPools_.getSlot(id);
|
||||||
|
20
src/ArduinoJson/Memory/ResourceManagerImpl.hpp
Normal file
20
src/ArduinoJson/Memory/ResourceManagerImpl.hpp
Normal file
@ -0,0 +1,20 @@
|
|||||||
|
// ArduinoJson - https://arduinojson.org
|
||||||
|
// Copyright © 2014-2024, Benoit BLANCHON
|
||||||
|
// MIT License
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <ArduinoJson/Collection/CollectionData.hpp>
|
||||||
|
#include <ArduinoJson/Memory/ResourceManager.hpp>
|
||||||
|
#include <ArduinoJson/Variant/VariantData.hpp>
|
||||||
|
|
||||||
|
ARDUINOJSON_BEGIN_PRIVATE_NAMESPACE
|
||||||
|
|
||||||
|
inline void ResourceManager::freeSlot(SlotWithId slot) {
|
||||||
|
if (slot->ownsKey())
|
||||||
|
dereferenceString(slot->key());
|
||||||
|
slot->data()->setNull(this);
|
||||||
|
variantPools_.freeSlot(slot);
|
||||||
|
}
|
||||||
|
|
||||||
|
ARDUINOJSON_END_PRIVATE_NAMESPACE
|
Reference in New Issue
Block a user