summaryrefslogtreecommitdiff
path: root/include
diff options
context:
space:
mode:
authorIlya Maximets <i.maximets@ovn.org>2021-11-22 01:09:31 +0100
committerIlya Maximets <i.maximets@ovn.org>2021-11-30 13:33:43 +0100
commit9d29990c21578a9a28b56b2ecdf8c18a1cb16b00 (patch)
treee8d22138aea3a4efe98fb35222bb27315dba3162 /include
parent19aa70168b062700668225ec3f931dd082ed91cd (diff)
downloadopenvswitch-9d29990c21578a9a28b56b2ecdf8c18a1cb16b00.tar.gz
json: Inline clone and destroy functions.
With the next commit reference counting of json objects will take significant part of the CPU time for ovsdb-server. Inlining them to reduce the cost of a function call. Acked-by: Mike Pattrick <mkp@redhat.com> Acked-by: Dumitru Ceara <dceara@redhat.com> Signed-off-by: Ilya Maximets <i.maximets@ovn.org>
Diffstat (limited to 'include')
-rw-r--r--include/openvswitch/json.h26
1 files changed, 24 insertions, 2 deletions
diff --git a/include/openvswitch/json.h b/include/openvswitch/json.h
index 0831a9cee..35b403c29 100644
--- a/include/openvswitch/json.h
+++ b/include/openvswitch/json.h
@@ -110,9 +110,9 @@ double json_real(const struct json *);
int64_t json_integer(const struct json *);
struct json *json_deep_clone(const struct json *);
-struct json *json_clone(const struct json *);
+static inline struct json *json_clone(const struct json *);
struct json *json_nullable_clone(const struct json *);
-void json_destroy(struct json *);
+static inline void json_destroy(struct json *);
size_t json_hash(const struct json *, size_t basis);
bool json_equal(const struct json *, const struct json *);
@@ -146,6 +146,28 @@ void json_to_ds(const struct json *, int flags, struct ds *);
bool json_string_unescape(const char *in, size_t in_len, char **outp);
void json_string_escape(const char *in, struct ds *out);
+
+/* Inline functions. */
+
+/* Returns 'json', with the reference count incremented. */
+static inline struct json *
+json_clone(const struct json *json_)
+{
+ struct json *json = CONST_CAST(struct json *, json_);
+ json->count++;
+ return json;
+}
+
+void json_destroy__(struct json *json);
+
+/* Frees 'json' and everything it points to, recursively. */
+static inline void
+json_destroy(struct json *json)
+{
+ if (json && !--json->count) {
+ json_destroy__(json);
+ }
+}
#ifdef __cplusplus
}