• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

bblanchon / ArduinoJson / 5645229289

pending completion
5645229289

push

github

bblanchon
Remains

3427 of 3441 relevant lines covered (99.59%)

8803.53 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

98.73
/src/ArduinoJson/Collection/CollectionImpl.hpp
1
// ArduinoJson - https://arduinojson.org
2
// Copyright © 2014-2023, Benoit BLANCHON
3
// MIT License
4

5
#pragma once
6

7
#include <ArduinoJson/Collection/CollectionData.hpp>
8
#include <ArduinoJson/Memory/Alignment.hpp>
9
#include <ArduinoJson/Strings/StringAdapters.hpp>
10
#include <ArduinoJson/Variant/VariantCompare.hpp>
11
#include <ArduinoJson/Variant/VariantData.hpp>
12

13
ARDUINOJSON_BEGIN_PRIVATE_NAMESPACE
14

15
inline CollectionIterator::CollectionIterator(VariantSlot* slot, SlotId slotId)
78,072✔
16
    : slot_(slot), currentId_(slotId) {
78,072✔
17
  nextId_ = slot_ ? slot_->next() : NULL_SLOT;
78,072✔
18
}
78,072✔
19

20
inline const char* CollectionIterator::key() const {
12,581✔
21
  ARDUINOJSON_ASSERT(slot_ != nullptr);
22
  return slot_->key();
12,581✔
23
}
24

25
inline void CollectionIterator::setKey(const char* s) {
698✔
26
  ARDUINOJSON_ASSERT(slot_ != nullptr);
27
  ARDUINOJSON_ASSERT(s != nullptr);
28
  return slot_->setKey(s);
698✔
29
}
30

31
inline void CollectionIterator::setKey(StringNode* s) {
1,387✔
32
  ARDUINOJSON_ASSERT(slot_ != nullptr);
33
  ARDUINOJSON_ASSERT(s != nullptr);
34
  return slot_->setKey(s);
1,387✔
35
}
36

37
inline bool CollectionIterator::ownsKey() const {
457✔
38
  ARDUINOJSON_ASSERT(slot_ != nullptr);
39
  return slot_->ownsKey();
457✔
40
}
41

42
inline void CollectionIterator::next(const ResourceManager* resources) {
275,435✔
43
  ARDUINOJSON_ASSERT(currentId_ != NULL_SLOT);
44
  slot_ = resources->getSlot(nextId_);
275,435✔
45
  currentId_ = nextId_;
275,435✔
46
  if (slot_)
275,435✔
47
    nextId_ = slot_->next();
271,650✔
48
}
275,435✔
49

50
inline CollectionData::iterator CollectionData::addSlot(
71,052✔
51
    ResourceManager* resources) {
52
  auto slot = resources->allocSlot();
71,052✔
53
  if (!slot)
71,052✔
54
    return {};
20✔
55
  if (tail_ != NULL_SLOT) {
71,032✔
56
    auto tail = resources->getSlot(tail_);
68,892✔
57
    tail->setNext(slot.id());
68,892✔
58
    tail_ = slot.id();
68,892✔
59
  } else {
60
    head_ = slot.id();
2,140✔
61
    tail_ = slot.id();
2,140✔
62
  }
63
  return iterator(slot, slot.id());
71,032✔
64
}
65

66
inline void CollectionData::clear(ResourceManager* resources) {
55✔
67
  auto next = head_;
55✔
68
  while (next != NULL_SLOT) {
200✔
69
    auto currId = next;
145✔
70
    auto slot = resources->getSlot(next);
145✔
71
    next = slot->next();
145✔
72
    releaseSlot(SlotWithId(slot, currId), resources);
145✔
73
  }
74

75
  head_ = NULL_SLOT;
55✔
76
  tail_ = NULL_SLOT;
55✔
77
}
55✔
78

79
inline SlotWithId CollectionData::getPreviousSlot(
41✔
80
    VariantSlot* target, const ResourceManager* resources) const {
81
  auto prev = SlotWithId();
41✔
82
  auto currentId = head_;
41✔
83
  while (currentId != NULL_SLOT) {
68✔
84
    auto currentSlot = resources->getSlot(currentId);
68✔
85
    if (currentSlot == target)
68✔
86
      return prev;
41✔
87
    prev = SlotWithId(currentSlot, currentId);
27✔
88
    currentId = currentSlot->next();
27✔
89
  }
90
  return SlotWithId();
×
91
}
92

93
inline void CollectionData::remove(iterator it, ResourceManager* resources) {
43✔
94
  if (it.done())
43✔
95
    return;
2✔
96
  auto curr = it.slot_;
41✔
97
  auto prev = getPreviousSlot(curr, resources);
41✔
98
  auto next = curr->next();
41✔
99
  if (prev)
41✔
100
    prev->setNext(next);
23✔
101
  else
102
    head_ = next;
18✔
103
  if (next == NULL_SLOT)
41✔
104
    tail_ = prev.id();
19✔
105
  releaseSlot({it.slot_, it.currentId_}, resources);
41✔
106
}
107

108
inline size_t CollectionData::nesting(const ResourceManager* resources) const {
16✔
109
  size_t maxChildNesting = 0;
16✔
110
  for (auto it = createIterator(resources); !it.done(); it.next(resources)) {
22✔
111
    size_t childNesting = it->nesting(resources);
6✔
112
    if (childNesting > maxChildNesting)
6✔
113
      maxChildNesting = childNesting;
4✔
114
  }
115
  return maxChildNesting + 1;
16✔
116
}
117

118
inline size_t CollectionData::size(const ResourceManager* resources) const {
356✔
119
  size_t count = 0;
356✔
120
  for (auto it = createIterator(resources); !it.done(); it.next(resources))
132,049✔
121
    count++;
131,693✔
122
  return count;
356✔
123
}
124

125
inline void CollectionData::releaseSlot(SlotWithId slot,
186✔
126
                                        ResourceManager* resources) {
127
  if (slot->ownsKey())
186✔
128
    resources->dereferenceString(slot->key());
7✔
129
  slot->data()->setNull(resources);
186✔
130
  resources->freeSlot(slot);
186✔
131
}
186✔
132

133
ARDUINOJSON_END_PRIVATE_NAMESPACE
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc