浏览代码

ResourceManager: move out-of-class definitions back in the class

Benoit Blanchon 6 月之前
父节点
当前提交
43548db37d

+ 0 - 1
extras/tests/ResourceManager/clear.cpp

@@ -3,7 +3,6 @@
 // MIT License
 
 #include <ArduinoJson/Memory/ResourceManager.hpp>
-#include <ArduinoJson/Memory/ResourceManagerImpl.hpp>
 #include <ArduinoJson/Strings/StringAdapters.hpp>
 #include <catch.hpp>
 

+ 0 - 1
extras/tests/ResourceManager/shrinkToFit.cpp

@@ -3,7 +3,6 @@
 // MIT License
 
 #include <ArduinoJson/Memory/ResourceManager.hpp>
-#include <ArduinoJson/Memory/ResourceManagerImpl.hpp>
 #include <catch.hpp>
 
 #include "Allocators.hpp"

+ 0 - 1
extras/tests/ResourceManager/size.cpp

@@ -3,7 +3,6 @@
 // MIT License
 
 #include <ArduinoJson/Memory/ResourceManager.hpp>
-#include <ArduinoJson/Memory/ResourceManagerImpl.hpp>
 #include <catch.hpp>
 
 #include "Allocators.hpp"

+ 0 - 1
extras/tests/ResourceManager/swap.cpp

@@ -4,7 +4,6 @@
 
 #include <ArduinoJson/Memory/Alignment.hpp>
 #include <ArduinoJson/Memory/ResourceManager.hpp>
-#include <ArduinoJson/Memory/ResourceManagerImpl.hpp>
 #include <catch.hpp>
 
 #include "Allocators.hpp"

+ 0 - 1
src/ArduinoJson.hpp

@@ -45,7 +45,6 @@
 #include "ArduinoJson/Array/ElementProxy.hpp"
 #include "ArduinoJson/Array/Utilities.hpp"
 #include "ArduinoJson/Collection/CollectionImpl.hpp"
-#include "ArduinoJson/Memory/ResourceManagerImpl.hpp"
 #include "ArduinoJson/Object/MemberProxy.hpp"
 #include "ArduinoJson/Object/ObjectImpl.hpp"
 #include "ArduinoJson/Variant/ConverterImpl.hpp"

+ 34 - 6
src/ArduinoJson/Memory/ResourceManager.hpp

@@ -57,14 +57,42 @@ class ResourceManager {
     return overflowed_;
   }
 
-  Slot<VariantData> allocVariant();
-  void freeVariant(Slot<VariantData> slot);
-  VariantData* getVariant(SlotId id) const;
+  Slot<VariantData> allocVariant() {
+    auto slot = variantPools_.allocSlot(allocator_);
+    if (!slot) {
+      overflowed_ = true;
+      return {};
+    }
+    new (slot.ptr()) VariantData();
+    return slot;
+  }
+
+  void freeVariant(Slot<VariantData> slot) {
+    variantPools_.freeSlot(slot);
+  }
+
+  VariantData* getVariant(SlotId id) const {
+    return variantPools_.getSlot(id);
+  }
 
 #if ARDUINOJSON_USE_8_BYTE_POOL
-  Slot<EightByteValue> allocEightByte();
-  void freeEightByte(SlotId slot);
-  EightByteValue* getEightByte(SlotId id) const;
+  Slot<EightByteValue> allocEightByte() {
+    auto slot = eightBytePools_.allocSlot(allocator_);
+    if (!slot) {
+      overflowed_ = true;
+      return {};
+    }
+    return slot;
+  }
+
+  void freeEightByte(SlotId id) {
+    auto p = getEightByte(id);
+    eightBytePools_.freeSlot({p, id});
+  }
+
+  EightByteValue* getEightByte(SlotId id) const {
+    return eightBytePools_.getSlot(id);
+  }
 #endif
 
   template <typename TAdaptedString>

+ 0 - 50
src/ArduinoJson/Memory/ResourceManagerImpl.hpp

@@ -1,50 +0,0 @@
-// ArduinoJson - https://arduinojson.org
-// Copyright © 2014-2025, Benoit BLANCHON
-// MIT License
-
-#pragma once
-
-#include <ArduinoJson/Memory/ResourceManager.hpp>
-#include <ArduinoJson/Polyfills/alias_cast.hpp>
-
-ARDUINOJSON_BEGIN_PRIVATE_NAMESPACE
-
-inline Slot<VariantData> ResourceManager::allocVariant() {
-  auto slot = variantPools_.allocSlot(allocator_);
-  if (!slot) {
-    overflowed_ = true;
-    return {};
-  }
-  new (slot.ptr()) VariantData();
-  return slot;
-}
-
-inline void ResourceManager::freeVariant(Slot<VariantData> slot) {
-  variantPools_.freeSlot(slot);
-}
-
-inline VariantData* ResourceManager::getVariant(SlotId id) const {
-  return reinterpret_cast<VariantData*>(variantPools_.getSlot(id));
-}
-
-#if ARDUINOJSON_USE_8_BYTE_POOL
-inline Slot<EightByteValue> ResourceManager::allocEightByte() {
-  auto slot = eightBytePools_.allocSlot(allocator_);
-  if (!slot) {
-    overflowed_ = true;
-    return {};
-  }
-  return slot;
-}
-
-inline void ResourceManager::freeEightByte(SlotId id) {
-  auto p = getEightByte(id);
-  eightBytePools_.freeSlot({p, id});
-}
-
-inline EightByteValue* ResourceManager::getEightByte(SlotId id) const {
-  return eightBytePools_.getSlot(id);
-}
-#endif
-
-ARDUINOJSON_END_PRIVATE_NAMESPACE