Преглед изворни кода

Use only one byte for the reference counter on 8-bit platforms

Benoit Blanchon пре 2 година
родитељ
комит
d20e64187b
1 измењених фајлова са 6 додато и 1 уклоњено
  1. 6 1
      src/ArduinoJson/Memory/StringNode.hpp

+ 6 - 1
src/ArduinoJson/Memory/StringNode.hpp

@@ -7,6 +7,7 @@
 #include <ArduinoJson/Memory/Allocator.hpp>
 #include <ArduinoJson/Memory/Allocator.hpp>
 #include <ArduinoJson/Namespace.hpp>
 #include <ArduinoJson/Namespace.hpp>
 #include <ArduinoJson/Polyfills/assert.hpp>
 #include <ArduinoJson/Polyfills/assert.hpp>
+#include <ArduinoJson/Polyfills/integer.hpp>
 #include <ArduinoJson/Polyfills/limits.hpp>
 #include <ArduinoJson/Polyfills/limits.hpp>
 
 
 #include <stddef.h>  // offsetof
 #include <stddef.h>  // offsetof
@@ -15,9 +16,13 @@
 ARDUINOJSON_BEGIN_PRIVATE_NAMESPACE
 ARDUINOJSON_BEGIN_PRIVATE_NAMESPACE
 
 
 struct StringNode {
 struct StringNode {
+  // Use the same type as SlotId to store the reference count
+  // (there can never be more references than slots)
+  using references_type = uint_t<ARDUINOJSON_SLOT_ID_SIZE * 8>::type;
+
   struct StringNode* next;
   struct StringNode* next;
   uint16_t length;
   uint16_t length;
-  uint16_t references;
+  references_type references;
   char data[1];
   char data[1];
 
 
   static constexpr size_t maxLength = numeric_limits<uint16_t>::highest();
   static constexpr size_t maxLength = numeric_limits<uint16_t>::highest();