2
0
mirror of https://github.com/openvswitch/ovs synced 2025-09-05 08:45:23 +00:00

system-stats: Use "smap" instead of "shash".

"smap" is now the appropriate data structure for a string-to-string map.

Also changes ovsdb_datum_from_shash() into ovsdb_datum_from_smap() since
system-stats related code was the only client.

Signed-off-by: Ben Pfaff <blp@nicira.com>
This commit is contained in:
Ben Pfaff
2012-07-18 10:51:02 -07:00
parent 51c82a49d5
commit 57c8677b51
7 changed files with 66 additions and 54 deletions

View File

@@ -29,6 +29,7 @@
#include "ovsdb-parser.h"
#include "json.h"
#include "shash.h"
#include "smap.h"
#include "sort.h"
#include "unicode.h"
@@ -1524,27 +1525,26 @@ ovsdb_datum_to_bare(const struct ovsdb_datum *datum,
}
/* Initializes 'datum' as a string-to-string map whose contents are taken from
* 'sh'. Destroys 'sh'. */
* 'smap'. Destroys 'smap'. */
void
ovsdb_datum_from_shash(struct ovsdb_datum *datum, struct shash *sh)
ovsdb_datum_from_smap(struct ovsdb_datum *datum, struct smap *smap)
{
struct shash_node *node, *next;
struct smap_node *node, *next;
size_t i;
datum->n = shash_count(sh);
datum->n = smap_count(smap);
datum->keys = xmalloc(datum->n * sizeof *datum->keys);
datum->values = xmalloc(datum->n * sizeof *datum->values);
i = 0;
SHASH_FOR_EACH_SAFE (node, next, sh) {
datum->keys[i].string = node->name;
datum->values[i].string = node->data;
shash_steal(sh, node);
SMAP_FOR_EACH_SAFE (node, next, smap) {
smap_steal(smap, node,
&datum->keys[i].string, &datum->values[i].string);
i++;
}
assert(i == datum->n);
shash_destroy(sh);
smap_destroy(smap);
ovsdb_datum_sort_unique(datum, OVSDB_TYPE_STRING, OVSDB_TYPE_STRING);
}