"Daniel P. Berrange" <berrange(a)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(a)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://deltacloud.org:|
http://search.cpan.org/~danberr/:|
|: GnuPG: 7D3B9505 -o- F3C9 553F A1DA 4AC2 5648 23C1 B3DF F742
7D3B
9505 :|