An upcoming commit will add a caller that needs to format both the key and
the value.  That isn't cleanly possible with the current interface.

Signed-off-by: Ben Pfaff <b...@nicira.com>
---
 lib/smap.c |   11 ++++++++++-
 lib/smap.h |    3 ++-
 2 files changed, 12 insertions(+), 2 deletions(-)

diff --git a/lib/smap.c b/lib/smap.c
index 0d75733..7fe3ce4 100644
--- a/lib/smap.c
+++ b/lib/smap.c
@@ -1,4 +1,4 @@
-/* Copyright (c) 2012 Nicira, Inc.
+/* Copyright (c) 2012, 2014 Nicira, Inc.
  *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
@@ -53,6 +53,15 @@ smap_add(struct smap *smap, const char *key, const char 
*value)
                       hash_bytes(key, key_len, 0));
 }
 
+/* Adds 'key' paired with 'value' to 'smap'.  Takes ownership of 'key' and
+ * 'value' (which will eventually be freed with free()).  It is the caller's
+ * responsibility to avoid duplicate keys if desirable. */
+struct smap_node *
+smap_add_nocopy(struct smap *smap, char *key, char *value)
+{
+    return smap_add__(smap, key, value, hash_bytes(key, strlen(key), 0));
+}
+
 /* Attempts to add 'key' to 'smap' associated with 'value'.  If 'key' already
  * exists in 'smap', does nothing and returns false.  Otherwise, performs the
  * addition and returns true. */
diff --git a/lib/smap.h b/lib/smap.h
index 640c2a8..316cb20 100644
--- a/lib/smap.h
+++ b/lib/smap.h
@@ -1,4 +1,4 @@
-/* Copyright (c) 2012 Nicira, Inc.
+/* Copyright (c) 2012, 2014 Nicira, Inc.
  *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
@@ -42,6 +42,7 @@ void smap_init(struct smap *);
 void smap_destroy(struct smap *);
 
 struct smap_node *smap_add(struct smap *, const char *, const char *);
+struct smap_node *smap_add_nocopy(struct smap *, char *, char *);
 bool smap_add_once(struct smap *, const char *, const char *);
 void smap_add_format(struct smap *, const char *key, const char *, ...)
     PRINTF_FORMAT(3, 4);
-- 
1.7.10.4

_______________________________________________
dev mailing list
dev@openvswitch.org
http://openvswitch.org/mailman/listinfo/dev

Reply via email to