ofproto: Inline trivial functions.
[sliver-openvswitch.git] / lib / smap.c
index ff78598..0d75733 100644 (file)
@@ -15,7 +15,7 @@
 #include <config.h>
 #include "smap.h"
 
-#include <assert.h>
+#include <strings.h>
 
 #include "hash.h"
 #include "json.h"
@@ -125,16 +125,29 @@ smap_remove_node(struct smap *smap, struct smap_node *node)
     free(node);
 }
 
-/* Deletes 'node' from 'sh'.  Neither the node's key nor its value is freed;
- * instead, ownership is transferred to the caller.  Returns the node's key. */
-char *
-smap_steal(struct smap *smap, struct smap_node *node)
+/* Deletes 'node' from 'smap'.
+ *
+ * If 'keyp' is nonnull, stores the node's key in '*keyp' and transfers
+ * ownership to the caller.  Otherwise, frees the node's key.  Similarly for
+ * 'valuep' and the node's value. */
+void
+smap_steal(struct smap *smap, struct smap_node *node,
+           char **keyp, char **valuep)
 {
-    char *key = node->key;
+    if (keyp) {
+        *keyp = node->key;
+    } else {
+        free(node->key);
+    }
+
+    if (valuep) {
+        *valuep = node->value;
+    } else {
+        free(node->value);
+    }
 
     hmap_remove(&smap->map, &node->node);
     free(node);
-    return key;
 }
 
 /* Removes all key-value pairs from 'smap'. */
@@ -238,7 +251,7 @@ smap_sort(const struct smap *smap)
         SMAP_FOR_EACH (node, smap) {
             nodes[i++] = node;
         }
-        assert(i == n);
+        ovs_assert(i == n);
 
         qsort(nodes, n, sizeof *nodes, compare_nodes_by_key);