Skip to content

Commit 892c37d

Browse files
committed
Optimized JsonVariant::is<float>()
1 parent d8a1d1a commit 892c37d

File tree

3 files changed

+13
-11
lines changed

3 files changed

+13
-11
lines changed

src/ArduinoJson/Variant/VariantContent.hpp

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,15 +16,18 @@ namespace ARDUINOJSON_NAMESPACE {
1616
enum {
1717
VALUE_MASK = 0x7F,
1818

19-
VALUE_IS_OWNED = 0x01,
19+
OWNED_VALUE_BIT = 0x01,
2020
VALUE_IS_NULL = 0,
2121
VALUE_IS_LINKED_RAW = 0x02,
2222
VALUE_IS_OWNED_RAW = 0x03,
2323
VALUE_IS_LINKED_STRING = 0x04,
2424
VALUE_IS_OWNED_STRING = 0x05,
2525

26-
// CAUTION: no VALUE_IS_OWNED below
26+
// CAUTION: no OWNED_VALUE_BIT below
27+
2728
VALUE_IS_BOOLEAN = 0x06,
29+
30+
NUMBER_BIT = 0x08,
2831
VALUE_IS_UNSIGNED_INTEGER = 0x08,
2932
VALUE_IS_SIGNED_INTEGER = 0x0A,
3033
VALUE_IS_FLOAT = 0x0C,
@@ -33,7 +36,7 @@ enum {
3336
VALUE_IS_OBJECT = 0x20,
3437
VALUE_IS_ARRAY = 0x40,
3538

36-
KEY_IS_OWNED = 0x80
39+
OWNED_KEY_BIT = 0x80
3740
};
3841

3942
struct RawData {

src/ArduinoJson/Variant/VariantData.hpp

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -141,8 +141,7 @@ class VariantData {
141141
}
142142

143143
bool isFloat() const {
144-
return type() == VALUE_IS_FLOAT || type() == VALUE_IS_UNSIGNED_INTEGER ||
145-
type() == VALUE_IS_SIGNED_INTEGER;
144+
return (_flags & NUMBER_BIT) != 0;
146145
}
147146

148147
bool isString() const {
@@ -308,7 +307,7 @@ class VariantData {
308307
}
309308

310309
void movePointers(ptrdiff_t stringDistance, ptrdiff_t variantDistance) {
311-
if (_flags & VALUE_IS_OWNED)
310+
if (_flags & OWNED_VALUE_BIT)
312311
_content.asString += stringDistance;
313312
if (_flags & COLLECTION_MASK)
314313
_content.asCollection.movePointers(stringDistance, variantDistance);
@@ -320,7 +319,7 @@ class VariantData {
320319

321320
private:
322321
void setType(uint8_t t) {
323-
_flags &= KEY_IS_OWNED;
322+
_flags &= OWNED_KEY_BIT;
324323
_flags |= t;
325324
}
326325

src/ArduinoJson/Variant/VariantSlot.hpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ class VariantSlot {
7979

8080
void setKey(const char* k, storage_policies::store_by_copy) {
8181
ARDUINOJSON_ASSERT(k != NULL);
82-
_flags |= KEY_IS_OWNED;
82+
_flags |= OWNED_KEY_BIT;
8383
_key = k;
8484
}
8585

@@ -94,7 +94,7 @@ class VariantSlot {
9494
}
9595

9696
bool ownsKey() const {
97-
return (_flags & KEY_IS_OWNED) != 0;
97+
return (_flags & OWNED_KEY_BIT) != 0;
9898
}
9999

100100
void clear() {
@@ -104,9 +104,9 @@ class VariantSlot {
104104
}
105105

106106
void movePointers(ptrdiff_t stringDistance, ptrdiff_t variantDistance) {
107-
if (_flags & KEY_IS_OWNED)
107+
if (_flags & OWNED_KEY_BIT)
108108
_key += stringDistance;
109-
if (_flags & VALUE_IS_OWNED)
109+
if (_flags & OWNED_VALUE_BIT)
110110
_content.asString += stringDistance;
111111
if (_flags & COLLECTION_MASK)
112112
_content.asCollection.movePointers(stringDistance, variantDistance);

0 commit comments

Comments
 (0)