diff options
author | Lennart Poettering <lennart@poettering.net> | 2018-10-12 16:21:21 +0200 |
---|---|---|
committer | Lennart Poettering <lennart@poettering.net> | 2018-10-18 16:44:51 +0200 |
commit | 4fcb507a909c60d8568b17fc8a9dbb8c83029c01 (patch) | |
tree | 01db05de66a7990e75ddfc780a30a874402925ec /src/basic | |
parent | json: when creating an object, insist that every second item is a string (diff) | |
download | systemd-4fcb507a909c60d8568b17fc8a9dbb8c83029c01.tar.xz systemd-4fcb507a909c60d8568b17fc8a9dbb8c83029c01.zip |
json: minor optimization
instead of comparing the magic JsonVariants one by one, let's simply
compare that they lie within a specific range.
Diffstat (limited to 'src/basic')
-rw-r--r-- | src/basic/json-internal.h | 1 | ||||
-rw-r--r-- | src/basic/json.c | 13 |
2 files changed, 5 insertions, 9 deletions
diff --git a/src/basic/json-internal.h b/src/basic/json-internal.h index 6d195eb672..98e53ede10 100644 --- a/src/basic/json-internal.h +++ b/src/basic/json-internal.h @@ -35,6 +35,7 @@ assert_cc(sizeof(JsonValue) == 16U); #define JSON_VARIANT_MAGIC_EMPTY_STRING ((JsonVariant*) 7) #define JSON_VARIANT_MAGIC_EMPTY_ARRAY ((JsonVariant*) 8) #define JSON_VARIANT_MAGIC_EMPTY_OBJECT ((JsonVariant*) 9) +#define _JSON_VARIANT_MAGIC_MAX ((JsonVariant*) 10) enum { /* JSON tokens */ JSON_TOKEN_END, diff --git a/src/basic/json.c b/src/basic/json.c index 72e8e115ba..f3db01eb99 100644 --- a/src/basic/json.c +++ b/src/basic/json.c @@ -140,15 +140,10 @@ static bool json_source_equal(JsonSource *a, JsonSource *b) { DEFINE_TRIVIAL_CLEANUP_FUNC(JsonSource*, json_source_unref); static bool json_variant_is_magic(const JsonVariant *v) { - return v == JSON_VARIANT_MAGIC_TRUE || - v == JSON_VARIANT_MAGIC_FALSE || - v == JSON_VARIANT_MAGIC_NULL || - v == JSON_VARIANT_MAGIC_ZERO_INTEGER || - v == JSON_VARIANT_MAGIC_ZERO_UNSIGNED || - v == JSON_VARIANT_MAGIC_ZERO_REAL || - v == JSON_VARIANT_MAGIC_EMPTY_STRING || - v == JSON_VARIANT_MAGIC_EMPTY_ARRAY || - v == JSON_VARIANT_MAGIC_EMPTY_OBJECT; + if (!v) + return false; + + return v < _JSON_VARIANT_MAGIC_MAX; } static JsonVariant *json_variant_dereference(JsonVariant *v) { |