<br><tt><font size=2>"Daniel P. Berrange" <berrange@redhat.com>
wrote on 03/30/2010 11:55:33 AM:<br>
<br>
<br>
> Please respond to "Daniel P. Berrange"</font></tt>
<br><tt><font size=2>> <br>
> On Tue, Mar 30, 2010 at 11:26:47AM -0400, Stefan Berger wrote:<br>
> > A cosmetic change that makes the entries in the int-2-string
maps look<br>
> > more readable. Add some missing entries.<br>
> > <br>
> > Signed-off-by: Stefan Berger <stefanb@us.ibm.com><br>
> > <br>
> > <br>
> > ---<br>
> >  src/conf/nwfilter_conf.c |   97 ++++++++++++<br>
> +----------------------------------<br>
> >  1 file changed, 28 insertions(+), 69 deletions(-)<br>
> > <br>
> > Index: libvirt-acl/src/conf/nwfilter_conf.c<br>
> > ===================================================================<br>
> > --- libvirt-acl.orig/src/conf/nwfilter_conf.c<br>
> > +++ libvirt-acl/src/conf/nwfilter_conf.c<br>
> > @@ -105,6 +105,9 @@ struct int_map {<br>
> >      const char *val;<br>
> >  };<br>
> >  <br>
> > +#define INTMAP_ENTRY(ATT, VAL) { .attr = ATT, .val = VAL }<br>
> > +#define INTMAP_ENTRY_LAST      { .val = NULL
}<br>
> > +<br>
> >  <br>
> >  /*<br>
> >   * only one filter update allowed<br>
> > @@ -388,18 +391,10 @@ struct _virXMLAttr2Struct<br>
> >  <br>
> >  <br>
> >  static const struct int_map macProtoMap[] = {<br>
> > -    {<br>
> > -      .attr = ETHERTYPE_ARP,<br>
> > -      .val  = "arp",<br>
> > -    }, {<br>
> > -      .attr = ETHERTYPE_IP,<br>
> > -      .val  = "ipv4",<br>
> > -    }, {<br>
> > -      .attr = ETHERTYPE_IPV6,<br>
> > -      .val  = "ipv6",<br>
> > -    }, {<br>
> > -      .val  = NULL,<br>
> > -    }<br>
> > +    INTMAP_ENTRY(ETHERTYPE_ARP , "arp"),<br>
> > +    INTMAP_ENTRY(ETHERTYPE_IP  , "ipv4"),<br>
> > +    INTMAP_ENTRY(ETHERTYPE_IPV6, "ipv6"),<br>
> > +    INTMAP_ENTRY_LAST<br>
> >  };<br>
> <br>
> This should all really be replaced with a standard call to VIR_ENUM_DECL
+ <br>
> VIR_ENUM_IMPL which do compile time validation that you have the correct<br>
> number of strings to match the enum, and allow O(1) int to string
conversion,<br>
> though string to int is still O(n).</font></tt>
<br>
<br><tt><font size=2>ETHERTYPE_ARP has value 0x806. From my understanding
this wouldn't fit the VIR_ENUM_DECL macros. O(log(n)) is the best we could
do for int lookups... but I doubt it'd be worth the effort for the small
maps.</font></tt>
<br>
<br><tt><font size=2>   Regards,</font></tt>
<br><tt><font size=2>     Stefan</font></tt>
<br><tt><font size=2><br>
> <br>
> Regards,<br>
> Daniel<br>
> -- <br>
> |: Red Hat, Engineering, London    -o-   </font></tt><a href=http://people.redhat.com/berrange/:|><tt><font size=2>http://people.redhat.com/berrange/:|</font></tt></a><tt><font size=2><br>
> |: </font></tt><a href=http://libvirt.org/><tt><font size=2>http://libvirt.org</font></tt></a><tt><font size=2>
-o- </font></tt><a href="http://virt-manager.org/"><tt><font size=2>http://virt-manager.org</font></tt></a><tt><font size=2>
-o- </font></tt><a href=http://deltacloud.org:|/><tt><font size=2>http://deltacloud.org:|</font></tt></a><tt><font size=2><br>
> |: </font></tt><a href=http://autobuild.org/><tt><font size=2>http://autobuild.org</font></tt></a><tt><font size=2>
       -o-         </font></tt><a href=http://search.cpan.org/~danberr/:|><tt><font size=2>http://search.cpan.org/~danberr/:|</font></tt></a><tt><font size=2><br>
> |: GnuPG: 7D3B9505  -o-   F3C9 553F A1DA 4AC2 5648 23C1
B3DF F742 7D3B 9505 :|<br>
</font></tt>