8000 Reduced executable size · java64/ArduinoJson@e363991 · GitHub
[go: up one dir, main page]

Skip to content

Commit e363991

Browse files
committed
Reduced executable size
1 parent 6d290bd commit e363991

File tree

6 files changed

+152
-126
lines changed

6 files changed

+152
-126
lines changed

src/ArduinoJson/Data/ListNode.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ namespace Internals {
1515
// Used by List<T> and its iterators.
1616
template <typename T>
1717
struct ListNode : public Internals::JsonBufferAllocated {
18-
ListNode() throw() : next(NULL) {}
18+
ListNode() NOEXCEPT : next(NULL) {}
1919

2020
ListNode<T> *next;
2121
T content;

src/ArduinoJson/JsonArray.hpp

Lines changed: 28 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,11 @@ class JsonArray {
2121
public:
2222
typedef JsonArrayIterator iterator;
2323

24-
JsonArray() : _buffer(0), _data(0) {}
25-
explicit JsonArray(Internals::JsonBuffer* buf, Internals::JsonArrayData* arr)
24+
FORCE_INLINE JsonArray() : _buffer(0), _data(0) {}
25+
FORCE_INLINE JsonArray(Internals::JsonBuffer* buf,
26+
Internals::JsonArrayData* arr)
2627
: _buffer(buf), _data(arr) {}
27-
explicit JsonArray(Internals::JsonBuffer* buf)
28+
FORCE_INLINE explicit JsonArray(Internals::JsonBuffer* buf)
2829
: _buffer(buf), _data(new (buf) Internals::JsonArrayData()) {}
2930

3031
// Adds the specified value at the end of the array.
@@ -33,29 +34,29 @@ class JsonArray {
3334
// TValue = bool, long, int, short, float, double, serialized, JsonVariant,
3435
// std::string, String, JsonArrayData, JsonObject
3536
template <typename T>
36-
bool add(const T& value) {
37+
FORCE_INLINE bool add(const T& value) {
3738
return add_impl<const T&>(value);
3839
}
3940
//
4041
// bool add(TValue);
4142
// TValue = char*, const char*, const FlashStringHelper*
4243
template <typename T>
43-
bool add(T* value) {
44+
FORCE_INLINE bool add(T* value) {
4445
return add_impl<T*>(value);
4546
}
4647

47-
iterator begin() const {
48+
FORCE_INLINE iterator begin() const {
4849
if (!_data) return iterator();
4950
return iterator(_buffer, _data->begin());
5051
}
5152

52-
iterator end() const {
53+
FORCE_INLINE iterator end() const {
5354
return iterator();
5455
}
5556

5657
// Imports a 1D array
5758
template <typename T, size_t N>
58-
bool copyFrom(T (&array)[N]) {
59+
FORCE_INLINE bool copyFrom(T (&array)[N]) {
5960
return copyFrom(array, N);
6061
}
6162

@@ -84,7 +85,7 @@ class JsonArray {
8485

8586
// Exports a 1D array
8687
template <typename T, size_t N>
87-
size_t copyTo(T (&array)[N]) const {
88+
FORCE_INLINE size_t copyTo(T (&array)[N]) const {
8889
return copyTo(array, N);
8990
}
9091

@@ -106,39 +107,41 @@ class JsonArray {
106107
}
107108
}
108109

109-
JsonArray createNestedArray();
110-
JsonObject createNestedObject();
110+
FORCE_INLINE JsonArray createNestedArray();
111+
FORCE_INLINE JsonObject createNestedObject();
111112

112-
Internals::JsonArraySubscript operator[](size_t index);
113+
FORCE_INLINE Internals::JsonArraySubscript operator[](size_t index);
113114

114-
const Internals::JsonArraySubscript operator[](size_t index) const;
115+
FORCE_INLINE const Internals::JsonArraySubscript operator[](
116+
size_t index) const;
115117

116-
bool operator==(const JsonArray& rhs) const {
118+
FORCE_INLINE bool operator==(const JsonArray& rhs) const {
117119
return _data == rhs._data;
118120
}
119121

120122
// Gets the value at the specified index.
121123
template <typename T>
122-
typename Internals::JsonVariantAs<T>::type get(size_t index) const {
124+
FORCE_INLINE typename Internals::JsonVariantAs<T>::type get(
125+
size_t index) const {
123126
iterator it = begin() += index;
124127
return it != end() ? it->as<T>() : T();
125128
}
126129

127130
// Check the type of the value at specified index.
128131
template <typename T>
129-
bool is(size_t index) const {
132+
FORCE_INLINE bool is(size_t index) const {
130133
iterator it = begin() += index;
131134
return it != end() ? it->is<T>() : false;
132135
}
133136

134137
// Removes element at specified position.
135-
void remove(iterator it) {
138+
FORCE_INLINE void remove(iterator it) {
136139
if (!_data) return;
137140
_data->remove(it.internal());
138141
}
139142

140143
// Removes element at specified index.
141-
void remove(size_t index) {
144+
FORCE_INLINE void remove(size_t index) {
142145
remove(begin() += index);
143146
}
144147

@@ -148,30 +151,30 @@ class JsonArray {
148151
// TValue = bool, long, int, short, float, double, serialized, JsonVariant,
149152
// std::string, String, JsonArrayData, JsonObject
150153
template <typename T>
151-
bool set(size_t index, const T& value) {
154+
FORCE_INLINE bool set(size_t index, const T& value) {
152155
if (!_data) return false;
153156
return set_impl<const T&>(index, value);
154157
}
155158
//
156159
// bool add(size_t index, TValue);
157160
// TValue = char*, const char*, const FlashStringHelper*
158161
template <typename T>
159-
bool set(size_t index, T* value) {
162+
FORCE_INLINE bool set(size_t index, T* value) {
160163
if (!_data) return false;
161164
return set_impl<T*>(index, value);
162165
}
163166

164-
size_t size() const {
167+
FORCE_INLINE size_t size() const {
165168
if (!_data) return 0;
166169
return _data->size();
167170
}
168171

169-
bool isNull() const {
172+
FORCE_INLINE bool isNull() const {
170173
return _data == 0;
171174
}
172175

173176
template <typename Visitor>
174-
void visit(Visitor& visitor) const {
177+
FORCE_INLINE void visit(Visitor& visitor) const {
175178
if (_data)
176179
visitor.acceptArray(*_data);
177180
else
@@ -180,14 +183,14 @@ class JsonArray {
180183

181184
private:
182185
template <typename TValueRef>
183-
bool set_impl(size_t index, TValueRef value) {
186+
FORCE_INLINE bool set_impl(size_t index, TValueRef value) {
184187
iterator it = begin() += index;
185188
if (it == end()) return false;
186189
return it->set(value);
187190
}
188191

189192
template <typename TValueRef>
190-
bool add_impl(TValueRef value) {
193+
FORCE_INLINE bool add_impl(TValueRef value) {
191194
if (!_data) return false;
192195
iterator it = iterator(_buffer, _data->add(_buffer));
193196
if (it == end()) return false;

0 commit comments

Comments
 (0)
0