[libvirt] [PATCH] nwfilter: Make entries in a int-2-string map more readable

Stefan Berger stefanb at us.ibm.com
Tue Mar 30 20:59:50 UTC 2010


"Daniel P. Berrange" <berrange at redhat.com> wrote on 03/30/2010 11:55:33 
AM:


> Please respond to "Daniel P. Berrange"
> 
> On Tue, Mar 30, 2010 at 11:26:47AM -0400, Stefan Berger wrote:
> > A cosmetic change that makes the entries in the int-2-string maps look
> > more readable. Add some missing entries.
> > 
> > Signed-off-by: Stefan Berger <stefanb at us.ibm.com>
> > 
> > 
> > ---
> >  src/conf/nwfilter_conf.c |   97 ++++++++++++
> +----------------------------------
> >  1 file changed, 28 insertions(+), 69 deletions(-)
> > 
> > Index: libvirt-acl/src/conf/nwfilter_conf.c
> > ===================================================================
> > --- libvirt-acl.orig/src/conf/nwfilter_conf.c
> > +++ libvirt-acl/src/conf/nwfilter_conf.c
> > @@ -105,6 +105,9 @@ struct int_map {
> >      const char *val;
> >  };
> > 
> > +#define INTMAP_ENTRY(ATT, VAL) { .attr = ATT, .val = VAL }
> > +#define INTMAP_ENTRY_LAST      { .val = NULL }
> > +
> > 
> >  /*
> >   * only one filter update allowed
> > @@ -388,18 +391,10 @@ struct _virXMLAttr2Struct
> > 
> > 
> >  static const struct int_map macProtoMap[] = {
> > -    {
> > -      .attr = ETHERTYPE_ARP,
> > -      .val  = "arp",
> > -    }, {
> > -      .attr = ETHERTYPE_IP,
> > -      .val  = "ipv4",
> > -    }, {
> > -      .attr = ETHERTYPE_IPV6,
> > -      .val  = "ipv6",
> > -    }, {
> > -      .val  = NULL,
> > -    }
> > +    INTMAP_ENTRY(ETHERTYPE_ARP , "arp"),
> > +    INTMAP_ENTRY(ETHERTYPE_IP  , "ipv4"),
> > +    INTMAP_ENTRY(ETHERTYPE_IPV6, "ipv6"),
> > +    INTMAP_ENTRY_LAST
> >  };
> 
> This should all really be replaced with a standard call to VIR_ENUM_DECL 
+ 
> VIR_ENUM_IMPL which do compile time validation that you have the correct
> number of strings to match the enum, and allow O(1) int to string 
conversion,
> though string to int is still O(n).

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.

   Regards,
     Stefan

> 
> Regards,
> Daniel
> -- 
> |: Red Hat, Engineering, London    -o-   
http://people.redhat.com/berrange/:|
> |: http://libvirt.org -o- http://virt-manager.org -o- 
http://deltacloud.org:|
> |: http://autobuild.org        -o-         
http://search.cpan.org/~danberr/:|
> |: GnuPG: 7D3B9505  -o-   F3C9 553F A1DA 4AC2 5648 23C1 B3DF F742 7D3B 
9505 :|
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://listman.redhat.com/archives/libvir-list/attachments/20100330/a8a53fb4/attachment-0001.htm>


More information about the libvir-list mailing list