shash: Introduce new macros SHASH_FOR_EACH, SHASH_FOR_EACH_SAFE.
authorBen Pfaff <blp@nicira.com>
Wed, 22 Jul 2009 23:33:43 +0000 (16:33 -0700)
committerBen Pfaff <blp@nicira.com>
Thu, 30 Jul 2009 23:07:13 +0000 (16:07 -0700)
This is both more convenient and cleaner than using HMAP_FOR_EACH(_SAFE)
directly.

lib/shash.c
lib/shash.h
lib/unixctl.c

index f1785139d74f08bc7481d7fa4891da6b5d87295a..7bb8cd70b9bb59e12a18bf57e9c42bb1af329f37 100644 (file)
@@ -44,7 +44,7 @@ shash_clear(struct shash *sh)
 {
     struct shash_node *node, *next;
 
-    HMAP_FOR_EACH_SAFE (node, next, struct shash_node, node, &sh->map) {
+    SHASH_FOR_EACH_SAFE (node, next, sh) {
         hmap_remove(&sh->map, &node->node);
         free(node->name);
         free(node);
index 72d8302007462fb74f1d10066e04e77406182b3e..5794a20f4d3b0659e3bf7533fff228e734327459 100644 (file)
@@ -31,6 +31,13 @@ struct shash {
 
 #define SHASH_INITIALIZER(SHASH) { HMAP_INITIALIZER(&(SHASH)->map) }
 
+#define SHASH_FOR_EACH(SHASH_NODE, SHASH)                               \
+    HMAP_FOR_EACH (SHASH_NODE, struct shash_node, node, &(SHASH)->map)
+
+#define SHASH_FOR_EACH_SAFE(SHASH_NODE, NEXT, SHASH)                \
+    HMAP_FOR_EACH_SAFE (SHASH_NODE, NEXT, struct shash_node, node,  \
+                        &(SHASH)->map)
+
 void shash_init(struct shash *);
 void shash_destroy(struct shash *);
 void shash_clear(struct shash *);
index 526c3fe356cec18076b461378735bb0c5950e808..17bd6cb56981cf2748bcd973d2283744d887703e 100644 (file)
@@ -82,7 +82,7 @@ unixctl_help(struct unixctl_conn *conn, const char *args UNUSED)
     struct shash_node *node;
 
     ds_put_cstr(&ds, "The available commands are:\n");
-    HMAP_FOR_EACH (node, struct shash_node, node, &commands.map) {
+    SHASH_FOR_EACH (node, &commands) {
         ds_put_format(&ds, "\t%s\n", node->name);
     }
     unixctl_command_reply(conn, 214, ds_cstr(&ds));