@@ -28,59 +28,66 @@ inline void CollectionIterator::next(const ResourceManager* resources) {
2828inline CollectionImpl::iterator CollectionImpl::createIterator () const {
2929 if (!data_)
3030 return iterator ();
31- return iterator (resources_->getVariant (data_->head ), data_->head );
31+ auto coll = getCollectionData ();
32+ return iterator (resources_->getVariant (coll->head ), coll->head );
3233}
3334
3435inline void CollectionImpl::appendOne (Slot<VariantData> slot) {
35- ARDUINOJSON_ASSERT (data_ != nullptr );
3636 ARDUINOJSON_ASSERT (resources_ != nullptr );
3737
38- if (data_->tail != NULL_SLOT) {
39- auto tail = resources_->getVariant (data_->tail );
38+ auto coll = getCollectionData ();
39+
40+ if (coll->tail != NULL_SLOT) {
41+ auto tail = resources_->getVariant (coll->tail );
4042 tail->next = slot.id ();
41- data_ ->tail = slot.id ();
43+ coll ->tail = slot.id ();
4244 } else {
43- data_ ->head = slot.id ();
44- data_ ->tail = slot.id ();
45+ coll ->head = slot.id ();
46+ coll ->tail = slot.id ();
4547 }
4648}
4749
4850inline void CollectionImpl::appendPair (Slot<VariantData> key,
4951 Slot<VariantData> value) {
50- ARDUINOJSON_ASSERT (data_ != nullptr );
5152 ARDUINOJSON_ASSERT (resources_ != nullptr );
5253
54+ auto coll = getCollectionData ();
55+
5356 key->next = value.id ();
5457
55- if (data_ ->tail != NULL_SLOT) {
56- auto tail = resources_->getVariant (data_ ->tail );
58+ if (coll ->tail != NULL_SLOT) {
59+ auto tail = resources_->getVariant (coll ->tail );
5760 tail->next = key.id ();
58- data_ ->tail = value.id ();
61+ coll ->tail = value.id ();
5962 } else {
60- data_ ->head = key.id ();
61- data_ ->tail = value.id ();
63+ coll ->head = key.id ();
64+ coll ->tail = value.id ();
6265 }
6366}
6467
6568inline void CollectionImpl::clear () {
6669 if (!data_)
6770 return ;
68- auto next = data_->head ;
71+
72+ auto coll = getCollectionData ();
73+
74+ auto next = coll->head ;
6975 while (next != NULL_SLOT) {
7076 auto currId = next;
7177 auto slot = resources_->getVariant (next);
7278 next = slot->next ;
7379 resources_->freeVariant ({slot, currId});
7480 }
7581
76- data_ ->head = NULL_SLOT;
77- data_ ->tail = NULL_SLOT;
82+ coll ->head = NULL_SLOT;
83+ coll ->tail = NULL_SLOT;
7884}
7985
8086inline Slot<VariantData> CollectionImpl::getPreviousSlot (
8187 VariantData* target) const {
88+ auto coll = getCollectionData ();
8289 auto prev = Slot<VariantData>();
83- auto currentId = data_ ->head ;
90+ auto currentId = coll ->head ;
8491 while (currentId != NULL_SLOT) {
8592 auto currentSlot = resources_->getVariant (currentId);
8693 if (currentSlot == target)
@@ -94,15 +101,16 @@ inline Slot<VariantData> CollectionImpl::getPreviousSlot(
94101inline void CollectionImpl::removeOne (iterator it) {
95102 if (it.done ())
96103 return ;
104+ auto coll = getCollectionData ();
97105 auto curr = it.slot_ ;
98106 auto prev = getPreviousSlot (curr);
99107 auto next = curr->next ;
100108 if (prev)
101109 prev->next = next;
102110 else
103- data_ ->head = next;
111+ coll ->head = next;
104112 if (next == NULL_SLOT)
105- data_ ->tail = prev.id ();
113+ coll ->tail = prev.id ();
106114 resources_->freeVariant ({it.slot_ , it.currentId_ });
107115}
108116
0 commit comments