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

bblanchon / ArduinoJson / 5641653306

pending completion
5641653306

push

github

bblanchon
friend member

32 of 32 new or added lines in 4 files covered. (100.0%)

3444 of 3458 relevant lines covered (99.6%)

8764.75 hits per line

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

98.78
/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,187✔
16
    : slot_(slot), currentId_(slotId) {
78,187✔
17
  nextId_ = slot_ ? slot_->next() : NULL_SLOT;
78,187✔
18
}
78,187✔
19

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

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

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

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

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

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

66
inline void CollectionData::clear(ResourceManager* resources) {
55✔
67
  for (auto it = createIterator(resources); !it.done(); it.next(resources))
200✔
68
    releaseSlot(it, resources);
145✔
69
  head_ = NULL_SLOT;
55✔
70
  tail_ = NULL_SLOT;
55✔
71
}
55✔
72

73
inline SlotWithId CollectionData::getPreviousSlot(
41✔
74
    VariantSlot* target, const ResourceManager* resources) const {
75
  auto prev = SlotWithId();
41✔
76
  auto currentId = head_;
41✔
77
  while (currentId != NULL_SLOT) {
68✔
78
    auto currentSlot = resources->getSlot(currentId);
68✔
79
    if (currentSlot == target)
68✔
80
      return prev;
41✔
81
    prev = SlotWithId(currentSlot, currentId);
27✔
82
    currentId = currentSlot->next();
27✔
83
  }
84
  return SlotWithId();
×
85
}
86

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

102
inline size_t CollectionData::memoryUsage(
16✔
103
    const ResourceManager* resources) const {
104
  size_t total = 0;
16✔
105
  for (auto it = createIterator(resources); !it.done(); it.next(resources)) {
30✔
106
    total += sizeof(VariantSlot) + it->memoryUsage(resources);
14✔
107
    if (it.ownsKey())
14✔
108
      total += sizeofString(strlen(it.key()));
1✔
109
  }
110
  return total;
16✔
111
}
112

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

123
inline size_t CollectionData::size(const ResourceManager* resources) const {
356✔
124
  size_t count = 0;
356✔
125
  for (auto it = createIterator(resources); !it.done(); it.next(resources))
132,049✔
126
    count++;
131,693✔
127
  return count;
356✔
128
}
129

130
inline void CollectionData::releaseSlot(iterator it,
186✔
131
                                        ResourceManager* resources) {
132
  ARDUINOJSON_ASSERT(!it.done());
133
  if (it.ownsKey())
186✔
134
    resources->dereferenceString(it.key());
7✔
135
  it->setNull(resources);
186✔
136
  resources->freeSlot(SlotWithId(it.slot_, it.currentId_));
186✔
137
}
186✔
138

139
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