diff options
author | Lennart Poettering <lennart@poettering.net> | 2021-11-25 10:25:03 +0100 |
---|---|---|
committer | Lennart Poettering <lennart@poettering.net> | 2021-11-25 14:22:31 +0100 |
commit | 0cdf6b14a5389fdeb75d67dde42c88de75962956 (patch) | |
tree | d9b3053975fd55469eb8954be7537fe911d2ad6c /src/test/test-json.c | |
parent | json: don't assert() if we add a NULL element via json_variant_set_field() (diff) | |
download | systemd-0cdf6b14a5389fdeb75d67dde42c88de75962956.tar.xz systemd-0cdf6b14a5389fdeb75d67dde42c88de75962956.zip |
json: add new JSON_BUILD_CONST_STRING() macro
This macro is like JSON_BUILD_STRING() but uses our json library's
ability to use literal strings directly as JsonVariant objects.
The changes all our codebase to use this new macro whenever we build
JSON objects from literal strings.
(I tried to make this automatic, i.e. to detect in JSON_BUILD_STRING()
whether something is a literal string nicely and thus do this stuff
automatically, but I couldn't find a way.)
This should reduce memory usage of our JSON code a bit. Constant strings
we use very often will now be shared and mapped directly from the ELF
image.
Diffstat (limited to 'src/test/test-json.c')
-rw-r--r-- | src/test/test-json.c | 14 |
1 files changed, 7 insertions, 7 deletions
diff --git a/src/test/test-json.c b/src/test/test-json.c index d1d551e746..926b246e17 100644 --- a/src/test/test-json.c +++ b/src/test/test-json.c @@ -333,16 +333,16 @@ static void test_build(void) { assert_se(json_build(&a, JSON_BUILD_OBJECT( JSON_BUILD_PAIR("x", JSON_BUILD_STRING("y")), - JSON_BUILD_PAIR("z", JSON_BUILD_STRING("a")), - JSON_BUILD_PAIR("b", JSON_BUILD_STRING("c")) + JSON_BUILD_PAIR("z", JSON_BUILD_CONST_STRING("a")), + JSON_BUILD_PAIR("b", JSON_BUILD_CONST_STRING("c")) )) >= 0); assert_se(json_build(&b, JSON_BUILD_OBJECT( JSON_BUILD_PAIR("x", JSON_BUILD_STRING("y")), JSON_BUILD_PAIR_CONDITION(false, "p", JSON_BUILD_STRING("q")), - JSON_BUILD_PAIR_CONDITION(true, "z", JSON_BUILD_STRING("a")), - JSON_BUILD_PAIR_CONDITION(false, "j", JSON_BUILD_ARRAY(JSON_BUILD_STRING("k"), JSON_BUILD_STRING("u"), JSON_BUILD_STRING("i"))), - JSON_BUILD_PAIR("b", JSON_BUILD_STRING("c")) + JSON_BUILD_PAIR_CONDITION(true, "z", JSON_BUILD_CONST_STRING("a")), + JSON_BUILD_PAIR_CONDITION(false, "j", JSON_BUILD_ARRAY(JSON_BUILD_STRING("k"), JSON_BUILD_CONST_STRING("u"), JSON_BUILD_CONST_STRING("i"))), + JSON_BUILD_PAIR("b", JSON_BUILD_CONST_STRING("c")) )) >= 0); assert_se(json_variant_equal(a, b)); @@ -435,8 +435,8 @@ static void test_normalize(void) { assert_se(json_build(&v, JSON_BUILD_OBJECT( JSON_BUILD_PAIR("b", JSON_BUILD_STRING("x")), - JSON_BUILD_PAIR("c", JSON_BUILD_STRING("y")), - JSON_BUILD_PAIR("a", JSON_BUILD_STRING("z")))) >= 0); + JSON_BUILD_PAIR("c", JSON_BUILD_CONST_STRING("y")), + JSON_BUILD_PAIR("a", JSON_BUILD_CONST_STRING("z")))) >= 0); assert_se(!json_variant_is_sorted(v)); assert_se(!json_variant_is_normalized(v)); |