@@ -22,59 +22,66 @@ inline void CollectionIterator::next(const ResourceManager* resources) {
2222inline CollectionImpl::iterator CollectionImpl::createIterator () const {
2323 if (!data_)
2424 return iterator ();
25- return iterator (resources_->getVariant (data_->head ), data_->head );
25+ auto coll = getCollectionData ();
26+ return iterator (resources_->getVariant (coll->head ), coll->head );
2627}
2728
2829inline void CollectionImpl::appendOne (Slot<VariantData> slot) {
29- ARDUINOJSON_ASSERT (data_ != nullptr );
3030 ARDUINOJSON_ASSERT (resources_ != nullptr );
3131
32- if (data_->tail != NULL_SLOT) {
33- auto tail = resources_->getVariant (data_->tail );
32+ auto coll = getCollectionData ();
33+
34+ if (coll->tail != NULL_SLOT) {
35+ auto tail = resources_->getVariant (coll->tail );
3436 tail->next = slot.id ();
35- data_ ->tail = slot.id ();
37+ coll ->tail = slot.id ();
3638 } else {
37- data_ ->head = slot.id ();
38- data_ ->tail = slot.id ();
39+ coll ->head = slot.id ();
40+ coll ->tail = slot.id ();
3941 }
4042}
4143
4244inline void CollectionImpl::appendPair (Slot<VariantData> key,
4345 Slot<VariantData> value) {
44- ARDUINOJSON_ASSERT (data_ != nullptr );
4546 ARDUINOJSON_ASSERT (resources_ != nullptr );
4647
48+ auto coll = getCollectionData ();
49+
4750 key->next = value.id ();
4851
49- if (data_ ->tail != NULL_SLOT) {
50- auto tail = resources_->getVariant (data_ ->tail );
52+ if (coll ->tail != NULL_SLOT) {
53+ auto tail = resources_->getVariant (coll ->tail );
5154 tail->next = key.id ();
52- data_ ->tail = value.id ();
55+ coll ->tail = value.id ();
5356 } else {
54- data_ ->head = key.id ();
55- data_ ->tail = value.id ();
57+ coll ->head = key.id ();
58+ coll ->tail = value.id ();
5659 }
5760}
5861
5962inline void CollectionImpl::clear () {
6063 if (!data_)
6164 return ;
62- auto next = data_->head ;
65+
66+ auto coll = getCollectionData ();
67+
68+ auto next = coll->head ;
6369 while (next != NULL_SLOT) {
6470 auto currId = next;
6571 auto slot = resources_->getVariant (next);
6672 next = slot->next ;
6773 resources_->freeVariant ({slot, currId});
6874 }
6975
70- data_ ->head = NULL_SLOT;
71- data_ ->tail = NULL_SLOT;
76+ coll ->head = NULL_SLOT;
77+ coll ->tail = NULL_SLOT;
7278}
7379
7480inline Slot<VariantData> CollectionImpl::getPreviousSlot (
7581 VariantData* target) const {
82+ auto coll = getCollectionData ();
7683 auto prev = Slot<VariantData>();
77- auto currentId = data_ ->head ;
84+ auto currentId = coll ->head ;
7885 while (currentId != NULL_SLOT) {
7986 auto currentSlot = resources_->getVariant (currentId);
8087 if (currentSlot == target)
@@ -88,15 +95,16 @@ inline Slot<VariantData> CollectionImpl::getPreviousSlot(
8895inline void CollectionImpl::removeOne (iterator it) {
8996 if (it.done ())
9097 return ;
98+ auto coll = getCollectionData ();
9199 auto curr = it.slot_ ;
92100 auto prev = getPreviousSlot (curr);
93101 auto next = curr->next ;
94102 if (prev)
95103 prev->next = next;
96104 else
97- data_ ->head = next;
105+ coll ->head = next;
98106 if (next == NULL_SLOT)
99- data_ ->tail = prev.id ();
107+ coll ->tail = prev.id ();
100108 resources_->freeVariant ({it.slot_ , it.currentId_ });
101109}
102110
0 commit comments