mirror of
				https://github.com/eledio-devices/thirdparty-ArduinoJson.git
				synced 2025-10-31 16:14:11 +01:00 
			
		
		
		
	Simplified string adapters
This commit is contained in:
		| @@ -7,6 +7,7 @@ | ||||
| #include <ArduinoJson/Memory/Alignment.hpp> | ||||
| #include <ArduinoJson/Polyfills/assert.hpp> | ||||
| #include <ArduinoJson/Polyfills/mpl/max.hpp> | ||||
| #include <ArduinoJson/Strings/StringAdapters.hpp> | ||||
| #include <ArduinoJson/Variant/VariantSlot.hpp> | ||||
|  | ||||
| #include <string.h>  // memmove | ||||
| @@ -64,7 +65,7 @@ class MemoryPool { | ||||
|       return 0; | ||||
|  | ||||
| #if ARDUINOJSON_ENABLE_STRING_DEDUPLICATION | ||||
|     const char* existingCopy = findString(str.begin()); | ||||
|     const char* existingCopy = findString(str); | ||||
|     if (existingCopy) | ||||
|       return existingCopy; | ||||
| #endif | ||||
| @@ -86,7 +87,7 @@ class MemoryPool { | ||||
|  | ||||
|   const char* saveStringFromFreeZone(size_t len) { | ||||
| #if ARDUINOJSON_ENABLE_STRING_DEDUPLICATION | ||||
|     const char* dup = findString(_left); | ||||
|     const char* dup = findString(adaptString(_left)); | ||||
|     if (dup) | ||||
|       return dup; | ||||
| #endif | ||||
| @@ -163,16 +164,11 @@ class MemoryPool { | ||||
|   } | ||||
|  | ||||
| #if ARDUINOJSON_ENABLE_STRING_DEDUPLICATION | ||||
|   template <typename TIterator> | ||||
|   const char* findString(TIterator str) { | ||||
|   template <typename TAdaptedString> | ||||
|   const char* findString(const TAdaptedString& str) { | ||||
|     for (char* next = _begin; next < _left; ++next) { | ||||
|       char* begin = next; | ||||
|  | ||||
|       // try to match | ||||
|       for (TIterator it = str; *it == *next; ++it) { | ||||
|         if (*next++ == 0) | ||||
|           return begin; | ||||
|       } | ||||
|       if (str.equals(next)) | ||||
|         return next; | ||||
|  | ||||
|       // jump to next terminator | ||||
|       while (*next) ++next; | ||||
|   | ||||
		Reference in New Issue
	
	Block a user