diff options
author | Ben Pfaff <blp@nicira.com> | 2015-09-08 18:39:25 -0700 |
---|---|---|
committer | Ben Pfaff <blp@nicira.com> | 2015-09-08 18:41:09 -0700 |
commit | aaf881c6c0c2c3149f9d1381b2f4730cf86a5746 (patch) | |
tree | cbc739e17b43a3cab70a0b9304f7164ea2d03612 /ovn/controller/ovn-controller.c | |
parent | 7f9b850474bfae061fa3ba68cb6e463c70c1b1cc (diff) | |
download | openvswitch-aaf881c6c0c2c3149f9d1381b2f4730cf86a5746.tar.gz |
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>
Diffstat (limited to 'ovn/controller/ovn-controller.c')
-rw-r--r-- | ovn/controller/ovn-controller.c | 16 |
1 files changed, 5 insertions, 11 deletions
diff --git a/ovn/controller/ovn-controller.c b/ovn/controller/ovn-controller.c index d705a16be..8c858bb21 100644 --- a/ovn/controller/ovn-controller.c +++ b/ovn/controller/ovn-controller.c @@ -95,10 +95,8 @@ create_br_int(struct controller_ctx *ctx, bridge = ovsrec_bridge_insert(ctx->ovs_idl_txn); ovsrec_bridge_set_name(bridge, bridge_name); ovsrec_bridge_set_fail_mode(bridge, "secure"); - struct smap other_config = SMAP_INITIALIZER(&other_config); - smap_add(&other_config, "disable-in-band", "true"); - ovsrec_bridge_set_other_config(bridge, &other_config); - smap_destroy(&other_config); + const struct smap oc = SMAP_CONST1(&oc, "disable-in-band", "true"); + ovsrec_bridge_set_other_config(bridge, &oc); ovsrec_bridge_set_ports(bridge, &port, 1); struct ovsrec_bridge **bridges; @@ -201,19 +199,15 @@ create_patch_port(struct controller_ctx *ctx, iface = ovsrec_interface_insert(ctx->ovs_idl_txn); ovsrec_interface_set_name(iface, port_name); ovsrec_interface_set_type(iface, "patch"); - struct smap options = SMAP_INITIALIZER(&options); - smap_add(&options, "peer", peer_port_name); + const struct smap options = SMAP_CONST1(&options, "peer", peer_port_name); ovsrec_interface_set_options(iface, &options); - smap_destroy(&options); struct ovsrec_port *port; port = ovsrec_port_insert(ctx->ovs_idl_txn); ovsrec_port_set_name(port, port_name); ovsrec_port_set_interfaces(port, &iface, 1); - 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); + const struct smap ids = SMAP_CONST1(&ids, "ovn-patch-port", network); + ovsrec_port_set_external_ids(port, &ids); struct ovsrec_port **ports; ports = xmalloc(sizeof *ports * (b1->n_ports + 1)); |