@@ -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
}
@@ -365,35 +365,33 @@ static void json_destroy_array(struct json_array *array);
/* Frees 'json' and everything it points to, recursively. */
void
-json_destroy(struct json *json)
+json_destroy__(struct json *json)
{
- if (json && !--json->count) {
- switch (json->type) {
- case JSON_OBJECT:
- json_destroy_object(json->object);
- break;
+ switch (json->type) {
+ case JSON_OBJECT:
+ json_destroy_object(json->object);
+ break;
- case JSON_ARRAY:
- json_destroy_array(&json->array);
- break;
+ case JSON_ARRAY:
+ json_destroy_array(&json->array);
+ break;
- case JSON_STRING:
- case JSON_SERIALIZED_OBJECT:
- free(json->string);
- break;
+ case JSON_STRING:
+ case JSON_SERIALIZED_OBJECT:
+ free(json->string);
+ break;
- case JSON_NULL:
- case JSON_FALSE:
- case JSON_TRUE:
- case JSON_INTEGER:
- case JSON_REAL:
- break;
+ case JSON_NULL:
+ case JSON_FALSE:
+ case JSON_TRUE:
+ case JSON_INTEGER:
+ case JSON_REAL:
+ break;
- case JSON_N_TYPES:
- OVS_NOT_REACHED();
- }
- free(json);
+ case JSON_N_TYPES:
+ OVS_NOT_REACHED();
}
+ free(json);
}
static void
@@ -459,15 +457,6 @@ json_deep_clone(const struct json *json)
}
}
-/* Returns 'json', with the reference count incremented. */
-struct json *
-json_clone(const struct json *json_)
-{
- struct json *json = CONST_CAST(struct json *, json_);
- json->count++;
- return json;
-}
-
struct json *
json_nullable_clone(const struct json *json)
{
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. Signed-off-by: Ilya Maximets <i.maximets@ovn.org> --- include/openvswitch/json.h | 26 +++++++++++++++++-- lib/json.c | 53 +++++++++++++++----------------------- 2 files changed, 45 insertions(+), 34 deletions(-)