X-Git-Url: http://git.onelab.eu/?a=blobdiff_plain;f=lib%2Fovsdb-parser.c;h=77460a8f5fda74a279be3bdc108bc16dbaae7b07;hb=d017eeb9f9ebcb46c24a67fd301b3e36cd26a04e;hp=5419467c71068a719b262fee70789a415d0c03fb;hpb=4d0101a0323397fbb4aa9f5bea4946a55880e045;p=sliver-openvswitch.git diff --git a/lib/ovsdb-parser.c b/lib/ovsdb-parser.c index 5419467c7..77460a8f5 100644 --- a/lib/ovsdb-parser.c +++ b/lib/ovsdb-parser.c @@ -1,4 +1,4 @@ -/* Copyright (c) 2009 Nicira Networks +/* Copyright (c) 2009, 2011 Nicira, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -32,7 +32,7 @@ ovsdb_parser_init(struct ovsdb_parser *parser, const struct json *json, parser->name = xvasprintf(name, args); va_end(args); - svec_init(&parser->used); + sset_init(&parser->used); parser->error = NULL; parser->json = (json && json->type == JSON_OBJECT ? json : NULL); @@ -41,8 +41,8 @@ ovsdb_parser_init(struct ovsdb_parser *parser, const struct json *json, } } -static bool -is_id(const char *string) +bool +ovsdb_parser_is_id(const char *string) { unsigned char c; @@ -80,12 +80,12 @@ ovsdb_parser_member(struct ovsdb_parser *parser, const char *name, return NULL; } - if ((value->type >= 0 && value->type < JSON_N_TYPES + if (((int) value->type >= 0 && value->type < JSON_N_TYPES && types & (1u << value->type)) || (types & OP_ID && value->type == JSON_STRING - && is_id(value->u.string))) + && ovsdb_parser_is_id(value->u.string))) { - svec_add(&parser->used, name); + sset_add(&parser->used, name); return value; } else { ovsdb_parser_raise_error(parser, "Type mismatch for member '%s'.", @@ -133,14 +133,12 @@ ovsdb_parser_finish(struct ovsdb_parser *parser) const struct shash *object = json_object(parser->json); size_t n_unused; - /* XXX this method of detecting unused members can be made cheaper */ - svec_sort_unique(&parser->used); - n_unused = shash_count(object) - parser->used.n; + n_unused = shash_count(object) - sset_count(&parser->used); if (n_unused) { struct shash_node *node; SHASH_FOR_EACH (node, object) { - if (!svec_contains(&parser->used, node->name)) { + if (!sset_contains(&parser->used, node->name)) { if (n_unused > 1) { ovsdb_parser_raise_error( parser, @@ -160,7 +158,7 @@ ovsdb_parser_finish(struct ovsdb_parser *parser) } free(parser->name); - svec_destroy(&parser->used); + sset_destroy(&parser->used); return parser->error; }