mirror of
https://github.com/bblanchon/ArduinoJson.git
synced 2025-07-30 02:37:35 +02:00
Store current and next slot id in CollectionIterator
This commit is contained in:
@ -18,7 +18,7 @@ class CollectionIterator {
|
|||||||
friend class CollectionData;
|
friend class CollectionData;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
CollectionIterator() : slot_(nullptr) {}
|
CollectionIterator() : slot_(nullptr), currentId_(NULL_SLOT) {}
|
||||||
|
|
||||||
void next(const ResourceManager* resources);
|
void next(const ResourceManager* resources);
|
||||||
|
|
||||||
@ -64,9 +64,10 @@ class CollectionIterator {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
CollectionIterator(VariantSlot* slot) : slot_(slot) {}
|
CollectionIterator(VariantSlot* slot, SlotId slotId);
|
||||||
|
|
||||||
VariantSlot* slot_;
|
VariantSlot* slot_;
|
||||||
|
SlotId currentId_, nextId_;
|
||||||
};
|
};
|
||||||
|
|
||||||
class CollectionData {
|
class CollectionData {
|
||||||
@ -84,7 +85,7 @@ class CollectionData {
|
|||||||
using iterator = CollectionIterator;
|
using iterator = CollectionIterator;
|
||||||
|
|
||||||
iterator createIterator(const ResourceManager* resources) const {
|
iterator createIterator(const ResourceManager* resources) const {
|
||||||
return iterator(resources->getSlot(head_));
|
return iterator(resources->getSlot(head_), head_);
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t memoryUsage(const ResourceManager*) const;
|
size_t memoryUsage(const ResourceManager*) const;
|
||||||
|
@ -12,6 +12,11 @@
|
|||||||
|
|
||||||
ARDUINOJSON_BEGIN_PRIVATE_NAMESPACE
|
ARDUINOJSON_BEGIN_PRIVATE_NAMESPACE
|
||||||
|
|
||||||
|
inline CollectionIterator::CollectionIterator(VariantSlot* slot, SlotId slotId)
|
||||||
|
: slot_(slot), currentId_(slotId) {
|
||||||
|
nextId_ = slot_ ? slot_->next() : NULL_SLOT;
|
||||||
|
}
|
||||||
|
|
||||||
inline const char* CollectionIterator::key() const {
|
inline const char* CollectionIterator::key() const {
|
||||||
ARDUINOJSON_ASSERT(slot_ != nullptr);
|
ARDUINOJSON_ASSERT(slot_ != nullptr);
|
||||||
return slot_->key();
|
return slot_->key();
|
||||||
@ -35,19 +40,18 @@ inline bool CollectionIterator::ownsKey() const {
|
|||||||
}
|
}
|
||||||
|
|
||||||
inline void CollectionIterator::next(const ResourceManager* resources) {
|
inline void CollectionIterator::next(const ResourceManager* resources) {
|
||||||
ARDUINOJSON_ASSERT(slot_ != nullptr);
|
ARDUINOJSON_ASSERT(currentId_ != NULL_SLOT);
|
||||||
auto nextId = slot_->next();
|
slot_ = resources->getSlot(nextId_);
|
||||||
if (nextId != NULL_SLOT)
|
currentId_ = nextId_;
|
||||||
slot_ = resources->getSlot(nextId);
|
if (slot_)
|
||||||
else
|
nextId_ = slot_->next();
|
||||||
slot_ = nullptr;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
inline CollectionData::iterator CollectionData::addSlot(
|
inline CollectionData::iterator CollectionData::addSlot(
|
||||||
ResourceManager* resources) {
|
ResourceManager* resources) {
|
||||||
auto slot = resources->allocSlot();
|
auto slot = resources->allocSlot();
|
||||||
if (!slot)
|
if (!slot)
|
||||||
return nullptr;
|
return {};
|
||||||
if (tail_ != NULL_SLOT) {
|
if (tail_ != NULL_SLOT) {
|
||||||
auto tail = resources->getSlot(tail_);
|
auto tail = resources->getSlot(tail_);
|
||||||
tail->setNext(slot.id());
|
tail->setNext(slot.id());
|
||||||
@ -56,7 +60,7 @@ inline CollectionData::iterator CollectionData::addSlot(
|
|||||||
head_ = slot.id();
|
head_ = slot.id();
|
||||||
tail_ = slot.id();
|
tail_ = slot.id();
|
||||||
}
|
}
|
||||||
return iterator(slot);
|
return iterator(slot, slot.id());
|
||||||
}
|
}
|
||||||
|
|
||||||
inline void CollectionData::clear(ResourceManager* resources) {
|
inline void CollectionData::clear(ResourceManager* resources) {
|
||||||
|
Reference in New Issue
Block a user