Skip to content

Commit a227703

Browse files
committed
ResourceManager: move out-of-class definitions back in the class
1 parent b7e0d73 commit a227703

File tree

4 files changed

+38
-57
lines changed

4 files changed

+38
-57
lines changed

.vscode/settings.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,5 +13,9 @@
1313
"[cmake]": {
1414
"editor.detectIndentation": false,
1515
"editor.insertSpaces": false,
16+
},
17+
"files.associations": {
18+
"*.vue": "vue",
19+
"thread": "cpp"
1620
}
1721
}

src/ArduinoJson.hpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,6 @@
4545
#include "ArduinoJson/Array/ElementProxy.hpp"
4646
#include "ArduinoJson/Array/Utilities.hpp"
4747
#include "ArduinoJson/Collection/CollectionImpl.hpp"
48-
#include "ArduinoJson/Memory/ResourceManagerImpl.hpp"
4948
#include "ArduinoJson/Object/MemberProxy.hpp"
5049
#include "ArduinoJson/Object/ObjectImpl.hpp"
5150
#include "ArduinoJson/Variant/ConverterImpl.hpp"

src/ArduinoJson/Memory/ResourceManager.hpp

Lines changed: 34 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -57,14 +57,42 @@ class ResourceManager {
5757
return overflowed_;
5858
}
5959

60-
Slot<VariantData> allocVariant();
61-
void freeVariant(Slot<VariantData> slot);
62-
VariantData* getVariant(SlotId id) const;
60+
Slot<VariantData> allocVariant() {
61+
auto slot = variantPools_.allocSlot(allocator_);
62+
if (!slot) {
63+
overflowed_ = true;
64+
return {};
65+
}
66+
new (slot.ptr()) VariantData();
67+
return slot;
68+
}
69+
70+
void freeVariant(Slot<VariantData> slot) {
71+
variantPools_.freeSlot(slot);
72+
}
73+
74+
VariantData* getVariant(SlotId id) const {
75+
return variantPools_.getSlot(id);
76+
}
6377

6478
#if ARDUINOJSON_USE_8_BYTE_POOL
65-
Slot<EightByteValue> allocEightByte();
66-
void freeEightByte(SlotId slot);
67-
EightByteValue* getEightByte(SlotId id) const;
79+
Slot<EightByteValue> allocEightByte() {
80+
auto slot = eightBytePools_.allocSlot(allocator_);
81+
if (!slot) {
82+
overflowed_ = true;
83+
return {};
84+
}
85+
return slot;
86+
}
87+
88+
void freeEightByte(SlotId id) {
89+
auto p = getEightByte(id);
90+
eightBytePools_.freeSlot({p, id});
91+
}
92+
93+
EightByteValue* getEightByte(SlotId id) const {
94+
return eightBytePools_.getSlot(id);
95+
}
6896
#endif
6997

7098
template <typename TAdaptedString>

src/ArduinoJson/Memory/ResourceManagerImpl.hpp

Lines changed: 0 additions & 50 deletions
This file was deleted.

0 commit comments

Comments
 (0)