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

bblanchon / ArduinoJson / 9131102872

17 May 2024 03:10PM CUT coverage: 99.553% (-0.001%) from 99.554%
9131102872

push

github

bblanchon
Move `CollectionData::releaseSlot()` to `ResourceManager::freeSlot()`

8 of 8 new or added lines in 2 files covered. (100.0%)

3790 of 3807 relevant lines covered (99.55%)

10947.29 hits per line

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

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

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

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

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

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

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

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

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

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

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

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

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

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

125
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