[ovs-git] [openvswitch/ovs] aaf881: smap: New macro SMAP_CONST1 for initializing immut...
GitHub
noreply at github.com
Wed Sep 9 01:41:31 UTC 2015
Branch: refs/heads/master
Home: https://github.com/openvswitch/ovs
Commit: aaf881c6c0c2c3149f9d1381b2f4730cf86a5746
https://github.com/openvswitch/ovs/commit/aaf881c6c0c2c3149f9d1381b2f4730cf86a5746
Author: Ben Pfaff <blp at nicira.com>
Date: 2015-09-08 (Tue, 08 Sep 2015)
Changed paths:
M lib/hmap.h
M lib/smap.h
M ovn/controller/encaps.c
M ovn/controller/ovn-controller.c
M ovn/northd/ovn-northd.c
M utilities/ovs-vsctl.c
Log Message:
-----------
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 at nicira.com>
Acked-by: Russell Bryant <rbryant at redhat.com>
More information about the git
mailing list