diff options
author | Luca Boccassi <bluca@debian.org> | 2023-06-26 17:13:49 +0200 |
---|---|---|
committer | Luca Boccassi <bluca@debian.org> | 2023-07-29 12:25:05 +0200 |
commit | 942c40c64cf888f8d66621f8a9d47a1a2970d12f (patch) | |
tree | 11fdb72f720c517264d15a23f9ce852144210942 /src/shared/serialize.h | |
parent | socket-util: add send/receive helpers for FD array (diff) | |
download | systemd-942c40c64cf888f8d66621f8a9d47a1a2970d12f.tar.xz systemd-942c40c64cf888f8d66621f8a9d47a1a2970d12f.zip |
serialize: add serialize_bool_elide() helper
In many case we serialize into objects that have been zero-initialized.
To save some time and resources when there are a lot of booleans, add a
helper that serializes only when the boolean is true.
Diffstat (limited to 'src/shared/serialize.h')
-rw-r--r-- | src/shared/serialize.h | 3 |
1 files changed, 3 insertions, 0 deletions
diff --git a/src/shared/serialize.h b/src/shared/serialize.h index 8fdc6dc304..8b6e0999f1 100644 --- a/src/shared/serialize.h +++ b/src/shared/serialize.h @@ -19,6 +19,9 @@ int serialize_strv(FILE *f, const char *key, char **l); static inline int serialize_bool(FILE *f, const char *key, bool b) { return serialize_item(f, key, yes_no(b)); } +static inline int serialize_bool_elide(FILE *f, const char *key, bool b) { + return b ? serialize_item(f, key, yes_no(b)) : 0; +} int deserialize_usec(const char *value, usec_t *timestamp); int deserialize_dual_timestamp(const char *value, dual_timestamp *t); |