diff options
| author | Ben Pfaff <blp@nicira.com> | 2011-08-22 14:52:21 -0700 |
|---|---|---|
| committer | Ben Pfaff <blp@nicira.com> | 2011-08-24 11:57:42 -0700 |
| commit | 6a6f8d167357a1f1751cdd54b9491c531a371ae1 (patch) | |
| tree | 82da21a7e944dd96fd397e17f20e3a2ff2e8ce32 /lib | |
| parent | 0233401f12fe5ef8f9d63d660d2bd3f739766025 (diff) | |
| download | openvswitch-6a6f8d167357a1f1751cdd54b9491c531a371ae1.tar.gz | |
ovsdb-data: Simplify converting an OVSDB datum to JSON by reordering logic.
Putting the "map" case first avoids duplicate tests.
Suggested-by: Reid Price <reid@nicira.com>
Diffstat (limited to 'lib')
| -rw-r--r-- | lib/ovsdb-data.c | 18 |
1 files changed, 9 insertions, 9 deletions
diff --git a/lib/ovsdb-data.c b/lib/ovsdb-data.c index 54ce72cf7..178181191 100644 --- a/lib/ovsdb-data.c +++ b/lib/ovsdb-data.c @@ -1278,30 +1278,30 @@ struct json * ovsdb_datum_to_json(const struct ovsdb_datum *datum, const struct ovsdb_type *type) { - if (datum->n == 1 && !ovsdb_type_is_map(type)) { - return ovsdb_atom_to_json(&datum->keys[0], type->key.type); - } else if (type->value.type == OVSDB_TYPE_VOID) { + if (ovsdb_type_is_map(type)) { struct json **elems; size_t i; elems = xmalloc(datum->n * sizeof *elems); for (i = 0; i < datum->n; i++) { - elems[i] = ovsdb_atom_to_json(&datum->keys[i], type->key.type); + elems[i] = json_array_create_2( + ovsdb_atom_to_json(&datum->keys[i], type->key.type), + ovsdb_atom_to_json(&datum->values[i], type->value.type)); } - return wrap_json("set", json_array_create(elems, datum->n)); + return wrap_json("map", json_array_create(elems, datum->n)); + } else if (datum->n == 1) { + return ovsdb_atom_to_json(&datum->keys[0], type->key.type); } else { struct json **elems; size_t i; elems = xmalloc(datum->n * sizeof *elems); for (i = 0; i < datum->n; i++) { - elems[i] = json_array_create_2( - ovsdb_atom_to_json(&datum->keys[i], type->key.type), - ovsdb_atom_to_json(&datum->values[i], type->value.type)); + elems[i] = ovsdb_atom_to_json(&datum->keys[i], type->key.type); } - return wrap_json("map", json_array_create(elems, datum->n)); + return wrap_json("set", json_array_create(elems, datum->n)); } } |
