diff options
author | Ilya Maximets <i.maximets@ovn.org> | 2021-11-22 01:09:32 +0100 |
---|---|---|
committer | Ilya Maximets <i.maximets@ovn.org> | 2021-11-30 13:34:03 +0100 |
commit | dec429168461052b62f205d211cb630c201bc28a (patch) | |
tree | f18cc07b5c8546d6ba082d95e67a9b25c3537405 /lib/ovsdb-data.h | |
parent | 9d29990c21578a9a28b56b2ecdf8c18a1cb16b00 (diff) | |
download | openvswitch-dec429168461052b62f205d211cb630c201bc28a.tar.gz |
ovsdb-data: Consolidate ovsdb atom and json strings.
ovsdb_atom_string and json_string are basically the same data structure
and ovsdb-server frequently needs to convert one to another. We can
avoid that by using json_string from the beginning for all ovsdb
strings. So, the conversion turns into simple json_clone(), i.e.
increment of a reference counter. This change gives a moderate
performance boost in some scenarios, improves the code clarity and
may be useful for future development.
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 'lib/ovsdb-data.h')
-rw-r--r-- | lib/ovsdb-data.h | 25 |
1 files changed, 8 insertions, 17 deletions
diff --git a/lib/ovsdb-data.h b/lib/ovsdb-data.h index f66ed3472..47115a7b8 100644 --- a/lib/ovsdb-data.h +++ b/lib/ovsdb-data.h @@ -19,6 +19,7 @@ #include <stdlib.h> #include "compiler.h" #include "ovsdb-types.h" +#include "openvswitch/json.h" #include "openvswitch/shash.h" #include "util.h" @@ -32,25 +33,16 @@ struct ds; struct ovsdb_symbol_table; struct smap; -struct ovsdb_atom_string { - char *string; - size_t n_refs; -}; - -static inline struct ovsdb_atom_string * +static inline struct json * ovsdb_atom_string_create_nocopy(char *str) { - struct ovsdb_atom_string *s = xzalloc(sizeof *s); - - s->string = str; - s->n_refs = 1; - return s; + return json_string_create_nocopy(str); } -static inline struct ovsdb_atom_string * +static inline struct json * ovsdb_atom_string_create(const char *str) { - return ovsdb_atom_string_create_nocopy(xstrdup(str)); + return json_string_create(str); } /* One value of an atomic type (given by enum ovs_atomic_type). */ @@ -58,7 +50,7 @@ union ovsdb_atom { int64_t integer; double real; bool boolean; - struct ovsdb_atom_string *s; + struct json *s; struct uuid uuid; }; @@ -88,9 +80,8 @@ ovsdb_atom_needs_destruction(enum ovsdb_atomic_type type) static inline void ovsdb_atom_destroy(union ovsdb_atom *atom, enum ovsdb_atomic_type type) { - if (type == OVSDB_TYPE_STRING && !--atom->s->n_refs) { - free(atom->s->string); - free(atom->s); + if (type == OVSDB_TYPE_STRING) { + json_destroy(atom->s); } } |