From efdd908807544de7bee8644fafc1400e6a32d936 Mon Sep 17 00:00:00 2001 From: Ben Pfaff Date: Wed, 30 Jun 2010 13:28:22 -0700 Subject: [PATCH] Simplify shash_find() followed by shash_add() into shash_add_once(). This is just a cleanup. --- lib/fatal-signal.c | 4 +--- lib/netdev.c | 4 +--- lib/ovsdb-idl.c | 6 ++---- vswitchd/bridge.c | 4 +--- 4 files changed, 5 insertions(+), 13 deletions(-) diff --git a/lib/fatal-signal.c b/lib/fatal-signal.c index 2e38fc51..0f360368 100644 --- a/lib/fatal-signal.c +++ b/lib/fatal-signal.c @@ -215,9 +215,7 @@ fatal_signal_add_file_to_unlink(const char *file) fatal_signal_add_hook(unlink_files, cancel_files, NULL, true); } - if (!shash_find(&files, file)) { - shash_add(&files, file, NULL); - } + shash_add_once(&files, file, NULL); } /* Unregisters 'file' from being unlinked when the program terminates via diff --git a/lib/netdev.c b/lib/netdev.c index dc27fd74..38f4dd58 100644 --- a/lib/netdev.c +++ b/lib/netdev.c @@ -1483,9 +1483,7 @@ netdev_monitor_cb(struct netdev_notifier *notifier) { struct netdev_monitor *monitor = notifier->aux; const char *name = netdev_get_name(notifier->netdev); - if (!shash_find(&monitor->changed_netdevs, name)) { - shash_add(&monitor->changed_netdevs, name, NULL); - } + shash_add_once(&monitor->changed_netdevs, name, NULL); } /* Attempts to add 'netdev' as a netdev monitored by 'monitor'. Returns 0 if diff --git a/lib/ovsdb-idl.c b/lib/ovsdb-idl.c index 62a33609..2537db7e 100644 --- a/lib/ovsdb-idl.c +++ b/lib/ovsdb-idl.c @@ -157,15 +157,13 @@ ovsdb_idl_create(const char *remote, const struct ovsdb_idl_class *class) struct ovsdb_idl_table *table = &idl->tables[i]; size_t j; - assert(!shash_find(&idl->table_by_name, tc->name)); - shash_add(&idl->table_by_name, tc->name, table); + shash_add_assert(&idl->table_by_name, tc->name, table); table->class = tc; shash_init(&table->columns); for (j = 0; j < tc->n_columns; j++) { const struct ovsdb_idl_column *column = &tc->columns[j]; - assert(!shash_find(&table->columns, column->name)); - shash_add(&table->columns, column->name, column); + shash_add_assert(&table->columns, column->name, column); } hmap_init(&table->rows); table->idl = idl; diff --git a/vswitchd/bridge.c b/vswitchd/bridge.c index d4a08b92..b7f068bf 100644 --- a/vswitchd/bridge.c +++ b/vswitchd/bridge.c @@ -645,9 +645,7 @@ bridge_reconfigure(const struct ovsrec_open_vswitch *ovs_cfg) shash_init(&cur_ifaces); for (i = 0; i < n_dpif_ports; i++) { const char *name = dpif_ports[i].devname; - if (!shash_find(&cur_ifaces, name)) { - shash_add(&cur_ifaces, name, NULL); - } + shash_add_once(&cur_ifaces, name, NULL); } free(dpif_ports); -- 2.30.2