On Wed, Mar 21, 2012 at 3:57 PM, Ethan Jackson <et...@nicira.com> wrote:
> This removes some boilerplate from the bridge. > > Signed-off-by: Ethan Jackson <et...@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
_______________________________________________ dev mailing list dev@openvswitch.org http://openvswitch.org/mailman/listinfo/dev