[ovs-dev] [PATCH 2/2] idl: New helpers for accessing string maps.
Reid Price
reid at nicira.com
Wed Mar 21 23:33:08 UTC 2012
On Wed, Mar 21, 2012 at 3:57 PM, Ethan Jackson <ethan at nicira.com> wrote:
> This removes some boilerplate from the bridge.
>
> Signed-off-by: Ethan Jackson <ethan at nicira.com>
> ---
>
> It actually turned out to be less difficult than I expected to do a binary
> search so I went ahead and did it.
>
> ---
> ovsdb/ovsdb-idlc.in | 50 +++++++++++++
> vswitchd/bridge.c | 208
> +++++++++++++++++++++++++--------------------------
> 2 files changed, 154 insertions(+), 104 deletions(-)
>
> diff --git a/ovsdb/ovsdb-idlc.in b/ovsdb/ovsdb-idlc.in
> <snip>
>
> # Table indexes.
> printEnum(["%sTABLE_%s" % (prefix.upper(), tableName.upper()) for
> tableName in sorted(schema.tables)] + ["%sN_TABLES" % prefix.upper()])
> print
> @@ -188,6 +203,22 @@ enum { sizeof_bool = sizeof(bool) };
> static bool inited;
> ''' % schema.idlHeader
>
> + try:
> + for table in schema.tables.itervalues():
> + for column in table.columns.itervalues():
> + if is_string_map(column):
> + print """\
> +static int
> +bsearch_strcmp(const void *a_, const void *b_)
> +{
> + char *const *a = a_;
> + char *const *b = b_;
> + return strcmp(*a, *b);
> +}"""
> + raise StopIteration
> + except StopIteration:
> + pass
> +
>
The StopIteration is non-standard, but seems quite reasonable. I think
a more canonical way would be to set some flag to False, iterate through
and set/break if you ever satisfy some condition.
Another option would be to do
have_string_maps = any(is_string_map(column)
for column in table.columns.itervalues()
for schema.tables.itervalues())
if have_string_maps:
print """\
static int
bsearch_strcmp(const void *a_, const void *b_)
{
char *const *a = a_;
char *const *b = b_;
return strcmp(*a, *b);
}"""
-Reid
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.openvswitch.org/pipermail/ovs-dev/attachments/20120321/28396744/attachment-0003.html>
More information about the dev
mailing list