summaryrefslogtreecommitdiff
path: root/src/shared/json.h
diff options
context:
space:
mode:
authorLennart Poettering <lennart@poettering.net>2021-11-25 10:25:03 +0100
committerLennart Poettering <lennart@poettering.net>2021-11-25 14:22:31 +0100
commit0cdf6b14a5389fdeb75d67dde42c88de75962956 (patch)
treed9b3053975fd55469eb8954be7537fe911d2ad6c /src/shared/json.h
parente2c7efd3293c6a14cd6d5baf8e0898da9a5c6d96 (diff)
downloadsystemd-0cdf6b14a5389fdeb75d67dde42c88de75962956.tar.gz
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/shared/json.h')
-rw-r--r--src/shared/json.h1
1 files changed, 1 insertions, 0 deletions
diff --git a/src/shared/json.h b/src/shared/json.h
index 0676e7bf5c..2248515ef7 100644
--- a/src/shared/json.h
+++ b/src/shared/json.h
@@ -259,6 +259,7 @@ enum {
#define JSON_BUILD_HEX(p, n) _JSON_BUILD_HEX, (const void*) { p }, (size_t) { n }
#define JSON_BUILD_ID128(id) _JSON_BUILD_ID128, (const sd_id128_t*) { &(id) }
#define JSON_BUILD_BYTE_ARRAY(v, n) _JSON_BUILD_BYTE_ARRAY, (const void*) { v }, (size_t) { n }
+#define JSON_BUILD_CONST_STRING(s) _JSON_BUILD_VARIANT, JSON_VARIANT_STRING_CONST(s)
int json_build(JsonVariant **ret, ...);
int json_buildv(JsonVariant **ret, va_list ap);