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

bblanchon / ArduinoJson / 9550679578

17 Jun 2024 03:44PM CUT coverage: 99.484%. Remained the same
9550679578

push

github

bblanchon
Add DevContainer files for Clang 13 to 17

3854 of 3874 relevant lines covered (99.48%)

10863.07 hits per line

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

98.77
/src/ArduinoJson/Collection/CollectionImpl.hpp
1
// ArduinoJson - https://arduinojson.org
2
// Copyright © 2014-2024, 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)
11,471✔
16
    : slot_(slot), currentId_(slotId) {
11,471✔
17
  nextId_ = slot_ ? slot_->next() : NULL_SLOT;
11,471✔
18
}
11,471✔
19

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

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

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

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

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

50
inline CollectionData::iterator CollectionData::addSlot(
4,958✔
51
    ResourceManager* resources) {
52
  auto slot = resources->allocSlot();
4,958✔
53
  if (!slot)
4,958✔
54
    return {};
16✔
55
  if (tail_ != NULL_SLOT) {
4,942✔
56
    auto tail = resources->getSlot(tail_);
2,886✔
57
    tail->setNext(slot.id());
2,886✔
58
    tail_ = slot.id();
2,886✔
59
  } else {
60
    head_ = slot.id();
2,056✔
61
    tail_ = slot.id();
2,056✔
62
  }
63
  return iterator(slot, slot.id());
4,942✔
64
}
65

66
inline void CollectionData::addSlot(SlotWithId slot,
66,275✔
67
                                    ResourceManager* resources) {
68
  if (tail_ != NULL_SLOT) {
66,275✔
69
    auto tail = resources->getSlot(tail_);
66,054✔
70
    tail->setNext(slot.id());
66,054✔
71
    tail_ = slot.id();
66,054✔
72
  } else {
73
    head_ = slot.id();
221✔
74
    tail_ = slot.id();
221✔
75
  }
76
}
66,275✔
77

78
inline void CollectionData::clear(ResourceManager* resources) {
68✔
79
  auto next = head_;
68✔
80
  while (next != NULL_SLOT) {
217✔
81
    auto currId = next;
149✔
82
    auto slot = resources->getSlot(next);
149✔
83
    next = slot->next();
149✔
84
    resources->freeSlot(SlotWithId(slot, currId));
149✔
85
  }
86

87
  head_ = NULL_SLOT;
68✔
88
  tail_ = NULL_SLOT;
68✔
89
}
68✔
90

91
inline SlotWithId CollectionData::getPreviousSlot(
45✔
92
    VariantSlot* target, const ResourceManager* resources) const {
93
  auto prev = SlotWithId();
45✔
94
  auto currentId = head_;
45✔
95
  while (currentId != NULL_SLOT) {
78✔
96
    auto currentSlot = resources->getSlot(currentId);
78✔
97
    if (currentSlot == target)
78✔
98
      return prev;
45✔
99
    prev = SlotWithId(currentSlot, currentId);
33✔
100
    currentId = currentSlot->next();
33✔
101
  }
102
  return SlotWithId();
×
103
}
104

105
inline void CollectionData::remove(iterator it, ResourceManager* resources) {
47✔
106
  if (it.done())
47✔
107
    return;
2✔
108
  auto curr = it.slot_;
45✔
109
  auto prev = getPreviousSlot(curr, resources);
45✔
110
  auto next = curr->next();
45✔
111
  if (prev)
45✔
112
    prev->setNext(next);
29✔
113
  else
114
    head_ = next;
16✔
115
  if (next == NULL_SLOT)
45✔
116
    tail_ = prev.id();
19✔
117
  resources->freeSlot({it.slot_, it.currentId_});
45✔
118
}
119

120
inline size_t CollectionData::nesting(const ResourceManager* resources) const {
30✔
121
  size_t maxChildNesting = 0;
30✔
122
  for (auto it = createIterator(resources); !it.done(); it.next(resources)) {
42✔
123
    size_t childNesting = it->nesting(resources);
12✔
124
    if (childNesting > maxChildNesting)
12✔
125
      maxChildNesting = childNesting;
8✔
126
  }
127
  return maxChildNesting + 1;
30✔
128
}
129

130
inline size_t CollectionData::size(const ResourceManager* resources) const {
359✔
131
  size_t count = 0;
359✔
132
  for (auto it = createIterator(resources); !it.done(); it.next(resources))
132,056✔
133
    count++;
131,697✔
134
  return count;
359✔
135
}
136

137
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