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

bblanchon / ArduinoJson / 5489391768

pending completion
5489391768

push

github

bblanchon
`VariantSlot` stores a `StringNode*` for owned keys

18 of 18 new or added lines in 5 files covered. (100.0%)

3406 of 3429 relevant lines covered (99.33%)

6529.06 hits per line

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

96.08
/src/ArduinoJson/Array/ArrayImpl.hpp
1
// ArduinoJson - https://arduinojson.org
2
// Copyright © 2014-2023, Benoit BLANCHON
3
// MIT License
4

5
#pragma once
6

7
#include <ArduinoJson/Array/ArrayData.hpp>
8
#include <ArduinoJson/Variant/VariantCompare.hpp>
9

10
ARDUINOJSON_BEGIN_PRIVATE_NAMESPACE
11

12
inline ArrayData::iterator ArrayData::at(size_t index) const {
422✔
13
  auto it = begin();
422✔
14
  while (it && index) {
666✔
15
    ++it;
244✔
16
    --index;
244✔
17
  }
18
  return it;
422✔
19
}
20

21
inline VariantData* ArrayData::addElement(ResourceManager* resources) {
68,624✔
22
  auto slot = resources->allocVariant();
68,624✔
23
  if (!slot)
68,624✔
24
    return nullptr;
19✔
25
  addSlot(slot);
68,605✔
26
  return slot->data();
68,605✔
27
}
28

29
inline bool ArrayData::copyFrom(const ArrayData& src,
12✔
30
                                ResourceManager* resources) {
31
  clear(resources);
12✔
32

33
  for (auto it = src.begin(); it; ++it) {
17✔
34
    auto var = addElement(resources);
6✔
35
    if (!var)
6✔
36
      return false;
1✔
37
    if (!var->copyFrom(*it, resources))
5✔
38
      return false;
×
39
  }
40
  return true;
11✔
41
}
42

43
inline bool ArrayData::equals(const ArrayData& other) const {
249✔
44
  auto a = begin();
249✔
45
  auto b = other.begin();
249✔
46

47
  for (;;) {
48
    if (!a && !b)  // both ended
665✔
49
      return true;
189✔
50
    if (!a || !b)  // one ended
476✔
51
      return false;
4✔
52
    if (compare(a.data(), b.data()) != COMPARE_RESULT_EQUAL)
472✔
53
      return false;
56✔
54
    ++a;
416✔
55
    ++b;
416✔
56
  }
57
}
58

59
inline VariantData* ArrayData::getOrAddElement(size_t index,
135✔
60
                                               ResourceManager* resources) {
61
  auto it = begin();
135✔
62
  while (it && index > 0) {
145✔
63
    ++it;
10✔
64
    index--;
10✔
65
  }
66
  if (!it)
135✔
67
    index++;
101✔
68
  VariantData* element = it.data();
135✔
69
  while (index > 0) {
249✔
70
    element = addElement(resources);
114✔
71
    if (!element)
114✔
72
      return nullptr;
×
73
    index--;
114✔
74
  }
75
  return element;
135✔
76
}
77

78
inline VariantData* ArrayData::getElement(size_t index) const {
412✔
79
  return at(index).data();
412✔
80
}
81

82
inline void ArrayData::removeElement(size_t index, ResourceManager* resources) {
10✔
83
  remove(at(index), resources);
10✔
84
}
10✔
85

86
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