mirror of
https://github.com/bblanchon/ArduinoJson.git
synced 2025-07-30 02:37:35 +02:00
Stop using CollectionIterator
in JsonSerializer
This reduces stack consumption and code size. See #2046
This commit is contained in:
@ -5,6 +5,7 @@ HEAD
|
|||||||
----
|
----
|
||||||
|
|
||||||
* Improve error messages when using `char` or `char*` (issue #2043)
|
* Improve error messages when using `char` or `char*` (issue #2043)
|
||||||
|
* Reduce `serializeJson()`'s size and stack usage (issue #2046)
|
||||||
|
|
||||||
v7.0.2 (2024-01-19)
|
v7.0.2 (2024-01-19)
|
||||||
------
|
------
|
||||||
|
@ -107,6 +107,10 @@ class CollectionData {
|
|||||||
return collection->remove(it, resources);
|
return collection->remove(it, resources);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
SlotId head() const {
|
||||||
|
return head_;
|
||||||
|
}
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
iterator addSlot(ResourceManager*);
|
iterator addSlot(ResourceManager*);
|
||||||
|
|
||||||
|
@ -22,16 +22,17 @@ class JsonSerializer : public VariantDataVisitor<size_t> {
|
|||||||
FORCE_INLINE size_t visit(const ArrayData& array) {
|
FORCE_INLINE size_t visit(const ArrayData& array) {
|
||||||
write('[');
|
write('[');
|
||||||
|
|
||||||
auto it = array.createIterator(resources_);
|
auto slotId = array.head();
|
||||||
|
|
||||||
while (!it.done()) {
|
while (slotId != NULL_SLOT) {
|
||||||
it->accept(*this);
|
auto slot = resources_->getSlot(slotId);
|
||||||
|
|
||||||
it.next(resources_);
|
slot->data()->accept(*this);
|
||||||
if (it.done())
|
|
||||||
break;
|
|
||||||
|
|
||||||
write(',');
|
slotId = slot->next();
|
||||||
|
|
||||||
|
if (slotId != NULL_SLOT)
|
||||||
|
write(',');
|
||||||
}
|
}
|
||||||
|
|
||||||
write(']');
|
write(']');
|
||||||
@ -41,18 +42,19 @@ class JsonSerializer : public VariantDataVisitor<size_t> {
|
|||||||
size_t visit(const ObjectData& object) {
|
size_t visit(const ObjectData& object) {
|
||||||
write('{');
|
write('{');
|
||||||
|
|
||||||
auto it = object.createIterator(resources_);
|
auto slotId = object.head();
|
||||||
|
|
||||||
while (!it.done()) {
|
while (slotId != NULL_SLOT) {
|
||||||
formatter_.writeString(it.key());
|
auto slot = resources_->getSlot(slotId);
|
||||||
|
|
||||||
|
formatter_.writeString(slot->key());
|
||||||
write(':');
|
write(':');
|
||||||
it->accept(*this);
|
slot->data()->accept(*this);
|
||||||
|
|
||||||
it.next(resources_);
|
slotId = slot->next();
|
||||||
if (it.done())
|
|
||||||
break;
|
|
||||||
|
|
||||||
write(',');
|
if (slotId != NULL_SLOT)
|
||||||
|
write(',');
|
||||||
}
|
}
|
||||||
|
|
||||||
write('}');
|
write('}');
|
||||||
|
Reference in New Issue
Block a user