json: minor optimization
instead of comparing the magic JsonVariants one by one, let's simply compare that they lie within a specific range.
This commit is contained in:
parent
d77e781fd0
commit
4fcb507a90
|
@ -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,
|
||||
|
|
|
@ -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) {
|
||||
|
|
Loading…
Reference in New Issue