Skip to content

Commit eab5ae2

Browse files
committed
Simplified string adapters
1 parent 2f0b3c0 commit eab5ae2

8 files changed

+7
-81
lines changed

src/ArduinoJson/Memory/MemoryPool.hpp

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
#include <ArduinoJson/Memory/Alignment.hpp>
88
#include <ArduinoJson/Polyfills/assert.hpp>
99
#include <ArduinoJson/Polyfills/mpl/max.hpp>
10+
#include <ArduinoJson/Strings/StringAdapters.hpp>
1011
#include <ArduinoJson/Variant/VariantSlot.hpp>
1112

1213
#include <string.h> // memmove
@@ -64,7 +65,7 @@ class MemoryPool {
6465
return 0;
6566

6667
#if ARDUINOJSON_ENABLE_STRING_DEDUPLICATION
67-
const char* existingCopy = findString(str.begin());
68+
const char* existingCopy = findString(str);
6869
if (existingCopy)
6970
return existingCopy;
7071
#endif
@@ -86,7 +87,7 @@ class MemoryPool {
8687

8788
const char* saveStringFromFreeZone(size_t len) {
8889
#if ARDUINOJSON_ENABLE_STRING_DEDUPLICATION
89-
const char* dup = findString(_left);
90+
const char* dup = findString(adaptString(_left));
9091
if (dup)
9192
return dup;
9293
#endif
@@ -163,16 +164,11 @@ class MemoryPool {
163164
}
164165

165166
#if ARDUINOJSON_ENABLE_STRING_DEDUPLICATION
166-
template <typename TIterator>
167-
const char* findString(TIterator str) {
167+
template <typename TAdaptedString>
168+
const char* findString(const TAdaptedString& str) {
168169
for (char* next = _begin; next < _left; ++next) {
169-
char* begin = next;
170-
171-
// try to match
172-
for (TIterator it = str; *it == *next; ++it) {
173-
if (*next++ == 0)
174-
return begin;
175-
}
170+
if (str.equals(next))
171+
return next;
176172

177173
// jump to next terminator
178174
while (*next) ++next;

src/ArduinoJson/Strings/ArduinoStringAdapter.hpp

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,10 +39,6 @@ class ArduinoStringAdapter {
3939
return _str->length();
4040
}
4141

42-
const char* begin() const {
43-
return _str->c_str();
44-
}
45-
4642
typedef storage_policies::store_by_copy storage_policy;
4743

4844
private:

src/ArduinoJson/Strings/ConstRamStringAdapter.hpp

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,10 +39,6 @@ class ConstRamStringAdapter {
3939
return _str;
4040
}
4141

42-
const char* begin() const {
43-
return _str;
44-
}
45-
4642
typedef storage_policies::store_by_address storage_policy;
4743

4844
protected:

src/ArduinoJson/Strings/FlashStringAdapter.hpp

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
#pragma once
66

77
#include <ArduinoJson/Polyfills/pgmspace.hpp>
8-
#include <ArduinoJson/Strings/FlashStringIterator.hpp>
98
#include <ArduinoJson/Strings/IsString.hpp>
109
#include <ArduinoJson/Strings/StoragePolicy.hpp>
1110

@@ -43,10 +42,6 @@ class FlashStringAdapter {
4342
return strlen_P(reinterpret_cast<const char*>(_str));
4443
}
4544

46-
FlashStringIterator begin() const {
47-
return FlashStringIterator(_str);
48-
}
49-
5045
typedef storage_policies::store_by_copy storage_policy;
5146

5247
private:

src/ArduinoJson/Strings/FlashStringIterator.hpp

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

src/ArduinoJson/Strings/SizedFlashStringAdapter.hpp

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
#pragma once
66

77
#include <ArduinoJson/Namespace.hpp>
8-
#include <ArduinoJson/Strings/FlashStringIterator.hpp>
98
#include <ArduinoJson/Strings/IsString.hpp>
109
#include <ArduinoJson/Strings/StoragePolicy.hpp>
1110

@@ -42,10 +41,6 @@ class SizedFlashStringAdapter {
4241
return _size;
4342
}
4443

45-
FlashStringIterator begin() const {
46-
return FlashStringIterator(_str);
47-
}
48-
4944
typedef storage_policies::store_by_copy storage_policy;
5045

5146
private:

src/ArduinoJson/Strings/SizedRamStringAdapter.hpp

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,10 +36,6 @@ class SizedRamStringAdapter {
3636
return _size;
3737
}
3838

39-
const char* begin() const {
40-
return _str;
41-
}
42-
4339
typedef storage_policies::store_by_copy storage_policy;
4440

4541
private:

src/ArduinoJson/Strings/StdStringAdapter.hpp

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -41,10 +41,6 @@ class StdStringAdapter {
4141
return _str->size();
4242
}
4343

44-
const char* begin() const {
45-
return _str->c_str();
46-
}
47-
4844
typedef storage_policies::store_by_copy storage_policy;
4945

5046
private:

0 commit comments

Comments
 (0)