|
|
@@ -17,28 +17,6 @@ inline CollectionIterator::CollectionIterator(VariantSlot* slot, SlotId slotId)
|
|
|
nextId_ = slot_ ? slot_->next() : NULL_SLOT;
|
|
|
}
|
|
|
|
|
|
-inline const char* CollectionIterator::key() const {
|
|
|
- ARDUINOJSON_ASSERT(slot_ != nullptr);
|
|
|
- return slot_->key();
|
|
|
-}
|
|
|
-
|
|
|
-inline void CollectionIterator::setKey(const char* s) {
|
|
|
- ARDUINOJSON_ASSERT(slot_ != nullptr);
|
|
|
- ARDUINOJSON_ASSERT(s != nullptr);
|
|
|
- return slot_->setKey(s);
|
|
|
-}
|
|
|
-
|
|
|
-inline void CollectionIterator::setKey(StringNode* s) {
|
|
|
- ARDUINOJSON_ASSERT(slot_ != nullptr);
|
|
|
- ARDUINOJSON_ASSERT(s != nullptr);
|
|
|
- return slot_->setKey(s);
|
|
|
-}
|
|
|
-
|
|
|
-inline bool CollectionIterator::ownsKey() const {
|
|
|
- ARDUINOJSON_ASSERT(slot_ != nullptr);
|
|
|
- return slot_->ownsKey();
|
|
|
-}
|
|
|
-
|
|
|
inline void CollectionIterator::next(const ResourceManager* resources) {
|
|
|
ARDUINOJSON_ASSERT(currentId_ != NULL_SLOT);
|
|
|
slot_ = resources->getSlot(nextId_);
|
|
|
@@ -47,11 +25,8 @@ inline void CollectionIterator::next(const ResourceManager* resources) {
|
|
|
nextId_ = slot_->next();
|
|
|
}
|
|
|
|
|
|
-inline CollectionData::iterator CollectionData::addSlot(
|
|
|
- ResourceManager* resources) {
|
|
|
- auto slot = resources->allocSlot();
|
|
|
- if (!slot)
|
|
|
- return {};
|
|
|
+inline void CollectionData::appendOne(SlotWithId slot,
|
|
|
+ const ResourceManager* resources) {
|
|
|
if (tail_ != NULL_SLOT) {
|
|
|
auto tail = resources->getSlot(tail_);
|
|
|
tail->setNext(slot.id());
|
|
|
@@ -60,18 +35,19 @@ inline CollectionData::iterator CollectionData::addSlot(
|
|
|
head_ = slot.id();
|
|
|
tail_ = slot.id();
|
|
|
}
|
|
|
- return iterator(slot, slot.id());
|
|
|
}
|
|
|
|
|
|
-inline void CollectionData::addSlot(SlotWithId slot,
|
|
|
- ResourceManager* resources) {
|
|
|
+inline void CollectionData::appendPair(SlotWithId key, SlotWithId value,
|
|
|
+ const ResourceManager* resources) {
|
|
|
+ key->setNext(value.id());
|
|
|
+
|
|
|
if (tail_ != NULL_SLOT) {
|
|
|
auto tail = resources->getSlot(tail_);
|
|
|
- tail->setNext(slot.id());
|
|
|
- tail_ = slot.id();
|
|
|
+ tail->setNext(key.id());
|
|
|
+ tail_ = value.id();
|
|
|
} else {
|
|
|
- head_ = slot.id();
|
|
|
- tail_ = slot.id();
|
|
|
+ head_ = key.id();
|
|
|
+ tail_ = value.id();
|
|
|
}
|
|
|
}
|
|
|
|
|
|
@@ -95,14 +71,14 @@ inline SlotWithId CollectionData::getPreviousSlot(
|
|
|
while (currentId != NULL_SLOT) {
|
|
|
auto currentSlot = resources->getSlot(currentId);
|
|
|
if (currentSlot == target)
|
|
|
- return prev;
|
|
|
+ break;
|
|
|
prev = SlotWithId(currentSlot, currentId);
|
|
|
currentId = currentSlot->next();
|
|
|
}
|
|
|
- return SlotWithId();
|
|
|
+ return prev;
|
|
|
}
|
|
|
|
|
|
-inline void CollectionData::remove(iterator it, ResourceManager* resources) {
|
|
|
+inline void CollectionData::removeOne(iterator it, ResourceManager* resources) {
|
|
|
if (it.done())
|
|
|
return;
|
|
|
auto curr = it.slot_;
|
|
|
@@ -117,6 +93,24 @@ inline void CollectionData::remove(iterator it, ResourceManager* resources) {
|
|
|
resources->freeSlot({it.slot_, it.currentId_});
|
|
|
}
|
|
|
|
|
|
+inline void CollectionData::removePair(ObjectData::iterator it,
|
|
|
+ ResourceManager* resources) {
|
|
|
+ if (it.done())
|
|
|
+ return;
|
|
|
+
|
|
|
+ auto keySlot = it.slot_;
|
|
|
+
|
|
|
+ auto valueId = it.nextId_;
|
|
|
+ auto valueSlot = resources->getSlot(valueId);
|
|
|
+
|
|
|
+ // remove value slot
|
|
|
+ keySlot->setNext(valueSlot->next());
|
|
|
+ resources->freeSlot({valueSlot, valueId});
|
|
|
+
|
|
|
+ // remove key slot
|
|
|
+ removeOne(it, resources);
|
|
|
+}
|
|
|
+
|
|
|
inline size_t CollectionData::nesting(const ResourceManager* resources) const {
|
|
|
size_t maxChildNesting = 0;
|
|
|
for (auto it = createIterator(resources); !it.done(); it.next(resources)) {
|