@@ -19,62 +19,82 @@ inline void CollectionIterator::next(const ResourceManager* resources) {
1919 currentId_ = nextId;
2020}
2121
22- inline CollectionImpl::iterator CollectionImpl::createIterator () const {
23- if (!data_)
24- return iterator ();
25- return iterator (resources_->getVariant (data_->head ), data_->head );
22+ inline CollectionImpl::iterator CollectionImpl::createIterator (
23+ VariantData* data, ResourceManager* resources) {
24+ ARDUINOJSON_ASSERT (data != nullptr );
25+ ARDUINOJSON_ASSERT (data->isCollection ());
26+ ARDUINOJSON_ASSERT (resources != nullptr );
27+ auto head = data->content .asCollection .head ;
28+ return iterator (resources->getVariant (head), head);
2629}
2730
28- inline void CollectionImpl::appendOne (Slot<VariantData> slot) {
29- ARDUINOJSON_ASSERT (data_ != nullptr );
30- ARDUINOJSON_ASSERT (resources_ != nullptr );
31+ inline void CollectionImpl::appendOne (Slot<VariantData> slot, VariantData* data,
32+ ResourceManager* resources) {
33+ ARDUINOJSON_ASSERT (data != nullptr );
34+ ARDUINOJSON_ASSERT (data->isCollection ());
35+ ARDUINOJSON_ASSERT (resources != nullptr );
36+
37+ auto coll = &data->content .asCollection ;
3138
32- if (data_ ->tail != NULL_SLOT) {
33- auto tail = resources_ ->getVariant (data_ ->tail );
39+ if (coll ->tail != NULL_SLOT) {
40+ auto tail = resources ->getVariant (coll ->tail );
3441 tail->next = slot.id ();
35- data_ ->tail = slot.id ();
42+ coll ->tail = slot.id ();
3643 } else {
37- data_ ->head = slot.id ();
38- data_ ->tail = slot.id ();
44+ coll ->head = slot.id ();
45+ coll ->tail = slot.id ();
3946 }
4047}
4148
4249inline void CollectionImpl::appendPair (Slot<VariantData> key,
43- Slot<VariantData> value) {
44- ARDUINOJSON_ASSERT (data_ != nullptr );
45- ARDUINOJSON_ASSERT (resources_ != nullptr );
50+ Slot<VariantData> value,
51+ VariantData* data,
52+ ResourceManager* resources) {
53+ ARDUINOJSON_ASSERT (data != nullptr );
54+ ARDUINOJSON_ASSERT (resources != nullptr );
4655
4756 key->next = value.id ();
4857
49- if (data_->tail != NULL_SLOT) {
50- auto tail = resources_->getVariant (data_->tail );
58+ auto coll = &data->content .asCollection ;
59+
60+ if (coll->tail != NULL_SLOT) {
61+ auto tail = resources->getVariant (coll->tail );
5162 tail->next = key.id ();
52- data_ ->tail = value.id ();
63+ coll ->tail = value.id ();
5364 } else {
54- data_ ->head = key.id ();
55- data_ ->tail = value.id ();
65+ coll ->head = key.id ();
66+ coll ->tail = value.id ();
5667 }
5768}
5869
59- inline void CollectionImpl::clear () {
60- if (!data_)
61- return ;
62- auto next = data_->head ;
70+ inline void CollectionImpl::clear (VariantData* data,
71+ ResourceManager* resources) {
72+ ARDUINOJSON_ASSERT (data != nullptr );
73+ ARDUINOJSON_ASSERT (data->isCollection ());
74+ ARDUINOJSON_ASSERT (resources != nullptr );
75+
76+ auto coll = &data->content .asCollection ;
77+
78+ auto next = coll->head ;
6379 while (next != NULL_SLOT) {
6480 auto currId = next;
65- auto slot = resources_ ->getVariant (next);
81+ auto slot = resources ->getVariant (next);
6682 next = slot->next ;
67- resources_ ->freeVariant ({slot, currId});
83+ resources ->freeVariant ({slot, currId});
6884 }
6985
70- data_ ->head = NULL_SLOT;
71- data_ ->tail = NULL_SLOT;
86+ coll ->head = NULL_SLOT;
87+ coll ->tail = NULL_SLOT;
7288}
7389
7490inline Slot<VariantData> CollectionImpl::getPreviousSlot (
7591 VariantData* target) const {
92+ ARDUINOJSON_ASSERT (data_ != nullptr );
93+ ARDUINOJSON_ASSERT (data_->isCollection ());
94+ ARDUINOJSON_ASSERT (resources_ != nullptr );
95+
7696 auto prev = Slot<VariantData>();
77- auto currentId = data_->head ;
97+ auto currentId = data_->content . asCollection . head ;
7898 while (currentId != NULL_SLOT) {
7999 auto currentSlot = resources_->getVariant (currentId);
80100 if (currentSlot == target)
@@ -91,12 +111,13 @@ inline void CollectionImpl::removeOne(iterator it) {
91111 auto curr = it.slot_ ;
92112 auto prev = getPreviousSlot (curr);
93113 auto next = curr->next ;
114+ auto coll = &data_->content .asCollection ;
94115 if (prev)
95116 prev->next = next;
96117 else
97- data_ ->head = next;
118+ coll ->head = next;
98119 if (next == NULL_SLOT)
99- data_ ->tail = prev.id ();
120+ coll ->tail = prev.id ();
100121 resources_->freeVariant ({it.slot_ , it.currentId_ });
101122}
102123
@@ -118,7 +139,7 @@ inline void CollectionImpl::removePair(ObjectImpl::iterator it) {
118139}
119140
120141inline size_t CollectionImpl::nesting () const {
121- if (!data_)
142+ if (!data_ || !data_-> isCollection () )
122143 return 0 ;
123144 size_t maxChildNesting = 0 ;
124145 for (auto it = createIterator (); !it.done (); it.next (resources_)) {
0 commit comments