smap: New macro SMAP_CONST1 for initializing immutable 1-member smaps.
authorBen Pfaff <blp@nicira.com>
Wed, 9 Sep 2015 01:39:25 +0000 (18:39 -0700)
committerBen Pfaff <blp@nicira.com>
Wed, 9 Sep 2015 01:41:09 +0000 (18:41 -0700)
commitaaf881c6c0c2c3149f9d1381b2f4730cf86a5746
treecbc739e17b43a3cab70a0b9304f7164ea2d03612
parent7f9b850474bfae061fa3ba68cb6e463c70c1b1cc
smap: New macro SMAP_CONST1 for initializing immutable 1-member smaps.

Reviewing the ovn-controller code I started to notice a common pattern:

    struct smap ext_ids = SMAP_INITIALIZER(&ext_ids);
    smap_add(&ext_ids, "ovn-patch-port", network);
    ovsrec_port_set_external_ids(port, &ext_ids);
    smap_destroy(&ext_ids);

This seemed like a bit too much code for something as simple as
initializing an smap with a single key-value pair.  This commit allows the
code to be reduced to just:

    const struct smap ids = SMAP_CONST1(&ids, "ovn-patch-port", network);
    ovsrec_port_set_external_ids(port, &ids);

This new form also eliminates multiple memory allocation and free
operations, but I doubt that has any real effect on performance;
the primary goal here is code readability.

Signed-off-by: Ben Pfaff <blp@nicira.com>
Acked-by: Russell Bryant <rbryant@redhat.com>
lib/hmap.h
lib/smap.h
ovn/controller/encaps.c
ovn/controller/ovn-controller.c
ovn/northd/ovn-northd.c
utilities/ovs-vsctl.c