Skip to content

Commit b017dfb

Browse files
committed
ResourceManager: move out-of-class definitions back in the class
1 parent 88769c4 commit b017dfb

File tree

7 files changed

+39
-62
lines changed

7 files changed

+39
-62
lines changed

extras/tests/ResourceManager/clear.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33
// MIT License
44

55
#include <ArduinoJson/Memory/ResourceManager.hpp>
6-
#include <ArduinoJson/Memory/ResourceManagerImpl.hpp>
76
#include <ArduinoJson/Strings/StringAdapters.hpp>
7+
88
#include <catch.hpp>
99

1010
using namespace ArduinoJson::detail;

extras/tests/ResourceManager/shrinkToFit.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
// MIT License
44

55
#include <ArduinoJson/Memory/ResourceManager.hpp>
6-
#include <ArduinoJson/Memory/ResourceManagerImpl.hpp>
6+
77
#include <catch.hpp>
88

99
#include "Allocators.hpp"

extras/tests/ResourceManager/size.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
// MIT License
44

55
#include <ArduinoJson/Memory/ResourceManager.hpp>
6-
#include <ArduinoJson/Memory/ResourceManagerImpl.hpp>
6+
77
#include <catch.hpp>
88

99
#include "Allocators.hpp"

extras/tests/ResourceManager/swap.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
#include <ArduinoJson/Memory/Alignment.hpp>
66
#include <ArduinoJson/Memory/ResourceManager.hpp>
7-
#include <ArduinoJson/Memory/ResourceManagerImpl.hpp>
7+
88
#include <catch.hpp>
99

1010
#include "Allocators.hpp"

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: 35 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -54,14 +54,43 @@ class ResourceManager {
5454
return overflowed_;
5555
}
5656

57-
Slot<VariantData> allocVariant();
58-
void freeVariant(Slot<VariantData> slot);
59-
VariantData* getVariant(SlotId id) const;
57+
Slot<VariantData> allocVariant() {
58+
auto slot = variantPools_.allocSlot(allocator_);
59+
if (!slot) {
60+
overflowed_ = true;
61+
return {};
62+
}
63+
new (slot.ptr()) VariantData();
64+
return slot;
65+
}
66+
67+
void freeVariant(Slot<VariantData> slot) {
68+
ARDUINOJSON_ASSERT(slot->type == VariantType::Null);
69+
variantPools_.freeSlot(slot);
70+
}
71+
72+
VariantData* getVariant(SlotId id) const {
73+
return reinterpret_cast<VariantData*>(variantPools_.getSlot(id));
74+
}
6075

6176
#if ARDUINOJSON_USE_8_BYTE_POOL
62-
Slot<EightByteValue> allocEightByte();
63-
void freeEightByte(SlotId slot);
64-
EightByteValue* getEightByte(SlotId id) const;
77+
Slot<EightByteValue> allocEightByte() {
78+
auto slot = eightBytePools_.allocSlot(allocator_);
79+
if (!slot) {
80+
overflowed_ = true;
81+
return {};
82+
}
83+
return slot;
84+
}
85+
86+
void freeEightByte(SlotId id) {
87+
auto p = getEightByte(id);
88+
eightBytePools_.freeSlot({p, id});
89+
}
90+
91+
EightByteValue* getEightByte(SlotId id) const {
92+
return eightBytePools_.getSlot(id);
93+
}
6594
#endif
6695

6796
template <typename TAdaptedString>

src/ArduinoJson/Memory/ResourceManagerImpl.hpp

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

0 commit comments

Comments
 (0)