Simplify shash_find() followed by shash_add() into shash_add_once().
authorBen Pfaff <blp@nicira.com>
Wed, 30 Jun 2010 20:28:22 +0000 (13:28 -0700)
committerBen Pfaff <blp@nicira.com>
Wed, 30 Jun 2010 23:48:55 +0000 (16:48 -0700)
This is just a cleanup.

lib/fatal-signal.c
lib/netdev.c
lib/ovsdb-idl.c
vswitchd/bridge.c

index 2e38fc5..0f36036 100644 (file)
@@ -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
index dc27fd7..38f4dd5 100644 (file)
@@ -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
index 62a3360..2537db7 100644 (file)
@@ -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;
index d4a08b9..b7f068b 100644 (file)
@@ -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);