Skip to content

Commit cb0dc94

Browse files
committed
Remove most FORCE_INLINEs
I kept only the ones that had a positive impact on code size AND no negative impact on stack memory. Fixes #2046
1 parent 72642e3 commit cb0dc94

File tree

12 files changed

+145
-152
lines changed

12 files changed

+145
-152
lines changed

CHANGELOG.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ HEAD
55
----
66

77
* Improve error messages when using `char` or `char*` (issue #2043)
8-
* Reduce `serializeJson()`'s size and stack usage (issue #2046)
8+
* Reduce stack consumption (issue #2046)
99
* Fix compatibility with GCC 4.8 (issue #2045)
1010

1111
v7.0.2 (2024-01-19)

src/ArduinoJson/Array/ElementProxy.hpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,25 +22,25 @@ class ElementProxy : public VariantRefBase<ElementProxy<TUpstream>>,
2222
ElementProxy(const ElementProxy& src)
2323
: upstream_(src.upstream_), index_(src.index_) {}
2424

25-
FORCE_INLINE ElementProxy& operator=(const ElementProxy& src) {
25+
ElementProxy& operator=(const ElementProxy& src) {
2626
this->set(src);
2727
return *this;
2828
}
2929

3030
template <typename T>
31-
FORCE_INLINE ElementProxy& operator=(const T& src) {
31+
ElementProxy& operator=(const T& src) {
3232
this->set(src);
3333
return *this;
3434
}
3535

3636
template <typename T>
37-
FORCE_INLINE ElementProxy& operator=(T* src) {
37+
ElementProxy& operator=(T* src) {
3838
this->set(src);
3939
return *this;
4040
}
4141

4242
private:
43-
FORCE_INLINE ResourceManager* getResourceManager() const {
43+
ResourceManager* getResourceManager() const {
4444
return VariantAttorney::getResourceManager(upstream_);
4545
}
4646

@@ -50,7 +50,7 @@ class ElementProxy : public VariantRefBase<ElementProxy<TUpstream>>,
5050
VariantAttorney::getResourceManager(upstream_));
5151
}
5252

53-
FORCE_INLINE VariantData* getOrCreateData() const {
53+
VariantData* getOrCreateData() const {
5454
auto data = VariantAttorney::getOrCreateData(upstream_);
5555
if (!data)
5656
return nullptr;

src/ArduinoJson/Array/JsonArray.hpp

Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,10 @@ class JsonArray : public detail::VariantOperators<JsonArray> {
2020
typedef JsonArrayIterator iterator;
2121

2222
// Constructs an unbound reference.
23-
FORCE_INLINE JsonArray() : data_(0), resources_(0) {}
23+
JsonArray() : data_(0), resources_(0) {}
2424

2525
// INTERNAL USE ONLY
26-
FORCE_INLINE JsonArray(detail::ArrayData* data,
27-
detail::ResourceManager* resources)
26+
JsonArray(detail::ArrayData* data, detail::ResourceManager* resources)
2827
: data_(data), resources_(resources) {}
2928

3029
// Returns a JsonVariant pointing to the array.
@@ -63,34 +62,34 @@ class JsonArray : public detail::VariantOperators<JsonArray> {
6362
// Appends a value to the array.
6463
// https://arduinojson.org/v7/api/jsonarray/add/
6564
template <typename T>
66-
FORCE_INLINE bool add(const T& value) const {
65+
bool add(const T& value) const {
6766
return add<JsonVariant>().set(value);
6867
}
6968

7069
// Appends a value to the array.
7170
// https://arduinojson.org/v7/api/jsonarray/add/
7271
template <typename T>
73-
FORCE_INLINE bool add(T* value) const {
72+
bool add(T* value) const {
7473
return add<JsonVariant>().set(value);
7574
}
7675

7776
// Returns an iterator to the first element of the array.
7877
// https://arduinojson.org/v7/api/jsonarray/begin/
79-
FORCE_INLINE iterator begin() const {
78+
iterator begin() const {
8079
if (!data_)
8180
return iterator();
8281
return iterator(data_->createIterator(resources_), resources_);
8382
}
8483

8584
// Returns an iterator following the last element of the array.
8685
// https://arduinojson.org/v7/api/jsonarray/end/
87-
FORCE_INLINE iterator end() const {
86+
iterator end() const {
8887
return iterator();
8988
}
9089

9190
// Copies an array.
9291
// https://arduinojson.org/v7/api/jsonarray/set/
93-
FORCE_INLINE bool set(JsonArrayConst src) const {
92+
bool set(JsonArrayConst src) const {
9493
if (!data_)
9594
return false;
9695

@@ -105,13 +104,13 @@ class JsonArray : public detail::VariantOperators<JsonArray> {
105104

106105
// Removes the element at the specified iterator.
107106
// https://arduinojson.org/v7/api/jsonarray/remove/
108-
FORCE_INLINE void remove(iterator it) const {
107+
void remove(iterator it) const {
109108
detail::ArrayData::remove(data_, it.iterator_, resources_);
110109
}
111110

112111
// Removes the element at the specified index.
113112
// https://arduinojson.org/v7/api/jsonarray/remove/
114-
FORCE_INLINE void remove(size_t index) const {
113+
void remove(size_t index) const {
115114
detail::ArrayData::removeElement(data_, index, resources_);
116115
}
117116

@@ -123,7 +122,7 @@ class JsonArray : public detail::VariantOperators<JsonArray> {
123122

124123
// Gets or sets the element at the specified index.
125124
// https://arduinojson.org/v7/api/jsonarray/subscript/
126-
FORCE_INLINE detail::ElementProxy<JsonArray> operator[](size_t index) const {
125+
detail::ElementProxy<JsonArray> operator[](size_t index) const {
127126
return {*this, index};
128127
}
129128

@@ -133,25 +132,25 @@ class JsonArray : public detail::VariantOperators<JsonArray> {
133132

134133
// Returns true if the reference is unbound.
135134
// https://arduinojson.org/v7/api/jsonarray/isnull/
136-
FORCE_INLINE bool isNull() const {
135+
bool isNull() const {
137136
return data_ == 0;
138137
}
139138

140139
// Returns true if the reference is bound.
141140
// https://arduinojson.org/v7/api/jsonarray/isnull/
142-
FORCE_INLINE operator bool() const {
141+
operator bool() const {
143142
return data_ != 0;
144143
}
145144

146145
// Returns the depth (nesting level) of the array.
147146
// https://arduinojson.org/v7/api/jsonarray/nesting/
148-
FORCE_INLINE size_t nesting() const {
147+
size_t nesting() const {
149148
return detail::VariantData::nesting(collectionToVariant(data_), resources_);
150149
}
151150

152151
// Returns the number of elements in the array.
153152
// https://arduinojson.org/v7/api/jsonarray/size/
154-
FORCE_INLINE size_t size() const {
153+
size_t size() const {
155154
return data_ ? data_->size(resources_) : 0;
156155
}
157156

src/ArduinoJson/Array/JsonArrayConst.hpp

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -23,29 +23,29 @@ class JsonArrayConst : public detail::VariantOperators<JsonArrayConst> {
2323

2424
// Returns an iterator to the first element of the array.
2525
// https://arduinojson.org/v7/api/jsonarrayconst/begin/
26-
FORCE_INLINE iterator begin() const {
26+
iterator begin() const {
2727
if (!data_)
2828
return iterator();
2929
return iterator(data_->createIterator(resources_), resources_);
3030
}
3131

3232
// Returns an iterator to the element following the last element of the array.
3333
// https://arduinojson.org/v7/api/jsonarrayconst/end/
34-
FORCE_INLINE iterator end() const {
34+
iterator end() const {
3535
return iterator();
3636
}
3737

3838
// Creates an unbound reference.
39-
FORCE_INLINE JsonArrayConst() : data_(0) {}
39+
JsonArrayConst() : data_(0) {}
4040

4141
// INTERNAL USE ONLY
42-
FORCE_INLINE JsonArrayConst(const detail::ArrayData* data,
43-
const detail::ResourceManager* resources)
42+
JsonArrayConst(const detail::ArrayData* data,
43+
const detail::ResourceManager* resources)
4444
: data_(data), resources_(resources) {}
4545

4646
// Returns the element at the specified index.
4747
// https://arduinojson.org/v7/api/jsonarrayconst/subscript/
48-
FORCE_INLINE JsonVariantConst operator[](size_t index) const {
48+
JsonVariantConst operator[](size_t index) const {
4949
return JsonVariantConst(
5050
detail::ArrayData::getElement(data_, index, resources_), resources_);
5151
}
@@ -56,25 +56,25 @@ class JsonArrayConst : public detail::VariantOperators<JsonArrayConst> {
5656

5757
// Returns true if the reference is unbound.
5858
// https://arduinojson.org/v7/api/jsonarrayconst/isnull/
59-
FORCE_INLINE bool isNull() const {
59+
bool isNull() const {
6060
return data_ == 0;
6161
}
6262

6363
// Returns true if the reference is bound.
6464
// https://arduinojson.org/v7/api/jsonarrayconst/isnull/
65-
FORCE_INLINE operator bool() const {
65+
operator bool() const {
6666
return data_ != 0;
6767
}
6868

6969
// Returns the depth (nesting level) of the array.
7070
// https://arduinojson.org/v7/api/jsonarrayconst/nesting/
71-
FORCE_INLINE size_t nesting() const {
71+
size_t nesting() const {
7272
return detail::VariantData::nesting(getData(), resources_);
7373
}
7474

7575
// Returns the number of elements in the array.
7676
// https://arduinojson.org/v7/api/jsonarrayconst/size/
77-
FORCE_INLINE size_t size() const {
77+
size_t size() const {
7878
return data_ ? data_->size(resources_) : 0;
7979
}
8080

src/ArduinoJson/Document/JsonDocument.hpp

Lines changed: 20 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -170,28 +170,26 @@ class JsonDocument : public detail::VariantOperators<const JsonDocument&> {
170170
// Gets or sets a root object's member.
171171
// https://arduinojson.org/v7/api/jsondocument/subscript/
172172
template <typename TString>
173-
FORCE_INLINE typename detail::enable_if<
174-
detail::IsString<TString>::value,
175-
detail::MemberProxy<JsonDocument&, TString>>::type
173+
typename detail::enable_if<detail::IsString<TString>::value,
174+
detail::MemberProxy<JsonDocument&, TString>>::type
176175
operator[](const TString& key) {
177176
return {*this, key};
178177
}
179178

180179
// Gets or sets a root object's member.
181180
// https://arduinojson.org/v7/api/jsondocument/subscript/
182181
template <typename TChar>
183-
FORCE_INLINE typename detail::enable_if<
184-
detail::IsString<TChar*>::value,
185-
detail::MemberProxy<JsonDocument&, TChar*>>::type
182+
typename detail::enable_if<detail::IsString<TChar*>::value,
183+
detail::MemberProxy<JsonDocument&, TChar*>>::type
186184
operator[](TChar* key) {
187185
return {*this, key};
188186
}
189187

190188
// Gets a root object's member.
191189
// https://arduinojson.org/v7/api/jsondocument/subscript/
192190
template <typename TString>
193-
FORCE_INLINE typename detail::enable_if<detail::IsString<TString>::value,
194-
JsonVariantConst>::type
191+
typename detail::enable_if<detail::IsString<TString>::value,
192+
JsonVariantConst>::type
195193
operator[](const TString& key) const {
196194
return JsonVariantConst(
197195
data_.getMember(detail::adaptString(key), &resources_), &resources_);
@@ -200,22 +198,22 @@ class JsonDocument : public detail::VariantOperators<const JsonDocument&> {
200198
// Gets a root object's member.
201199
// https://arduinojson.org/v7/api/jsondocument/subscript/
202200
template <typename TChar>
203-
FORCE_INLINE typename detail::enable_if<detail::IsString<TChar*>::value,
204-
JsonVariantConst>::type
201+
typename detail::enable_if<detail::IsString<TChar*>::value,
202+
JsonVariantConst>::type
205203
operator[](TChar* key) const {
206204
return JsonVariantConst(
207205
data_.getMember(detail::adaptString(key), &resources_), &resources_);
208206
}
209207

210208
// Gets or sets a root array's element.
211209
// https://arduinojson.org/v7/api/jsondocument/subscript/
212-
FORCE_INLINE detail::ElementProxy<JsonDocument&> operator[](size_t index) {
210+
detail::ElementProxy<JsonDocument&> operator[](size_t index) {
213211
return {*this, index};
214212
}
215213

216214
// Gets a root array's member.
217215
// https://arduinojson.org/v7/api/jsondocument/subscript/
218-
FORCE_INLINE JsonVariantConst operator[](size_t index) const {
216+
JsonVariantConst operator[](size_t index) const {
219217
return JsonVariantConst(data_.getElement(index, &resources_), &resources_);
220218
}
221219

@@ -240,47 +238,47 @@ class JsonDocument : public detail::VariantOperators<const JsonDocument&> {
240238
// Appends a value to the root array.
241239
// https://arduinojson.org/v7/api/jsondocument/add/
242240
template <typename TValue>
243-
FORCE_INLINE bool add(const TValue& value) {
241+
bool add(const TValue& value) {
244242
return add<JsonVariant>().set(value);
245243
}
246244

247245
// Appends a value to the root array.
248246
// https://arduinojson.org/v7/api/jsondocument/add/
249247
template <typename TChar>
250-
FORCE_INLINE bool add(TChar* value) {
248+
bool add(TChar* value) {
251249
return add<JsonVariant>().set(value);
252250
}
253251

254252
// Removes an element of the root array.
255253
// https://arduinojson.org/v7/api/jsondocument/remove/
256-
FORCE_INLINE void remove(size_t index) {
254+
void remove(size_t index) {
257255
detail::VariantData::removeElement(getData(), index, getResourceManager());
258256
}
259257

260258
// Removes a member of the root object.
261259
// https://arduinojson.org/v7/api/jsondocument/remove/
262260
template <typename TChar>
263-
FORCE_INLINE typename detail::enable_if<detail::IsString<TChar*>::value>::type
264-
remove(TChar* key) {
261+
typename detail::enable_if<detail::IsString<TChar*>::value>::type remove(
262+
TChar* key) {
265263
detail::VariantData::removeMember(getData(), detail::adaptString(key),
266264
getResourceManager());
267265
}
268266

269267
// Removes a member of the root object.
270268
// https://arduinojson.org/v7/api/jsondocument/remove/
271269
template <typename TString>
272-
FORCE_INLINE
273-
typename detail::enable_if<detail::IsString<TString>::value>::type
274-
remove(const TString& key) {
270+
271+
typename detail::enable_if<detail::IsString<TString>::value>::type remove(
272+
const TString& key) {
275273
detail::VariantData::removeMember(getData(), detail::adaptString(key),
276274
getResourceManager());
277275
}
278276

279-
FORCE_INLINE operator JsonVariant() {
277+
operator JsonVariant() {
280278
return getVariant();
281279
}
282280

283-
FORCE_INLINE operator JsonVariantConst() const {
281+
operator JsonVariantConst() const {
284282
return getVariant();
285283
}
286284

0 commit comments

Comments
 (0)