Permalink
Browse files

Add qdict_clone_shallow()

Signed-off-by: Kevin Wolf <kwolf@redhat.com>
Reviewed-by: Eric Blake <eblake@redhat.com>
Reviewed-by: Stefan Hajnoczi <stefanha@redhat.com>
Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
  • Loading branch information...
Kevin Wolf Stefan Hajnoczi
Kevin Wolf authored and Stefan Hajnoczi committed Mar 15, 2013
1 parent de9c0ce commit b382bc9a1504c7f7c112881695d08293b906b88f
Showing with 24 additions and 0 deletions.
  1. +2 −0 include/qapi/qmp/qdict.h
  2. +22 −0 qobject/qdict.c
View
@@ -64,4 +64,6 @@ int64_t qdict_get_try_int(const QDict *qdict, const char *key,
int qdict_get_try_bool(const QDict *qdict, const char *key, int def_value);
const char *qdict_get_try_str(const QDict *qdict, const char *key);
+QDict *qdict_clone_shallow(const QDict *src);
+
#endif /* QDICT_H */
View
@@ -400,6 +400,28 @@ const QDictEntry *qdict_next(const QDict *qdict, const QDictEntry *entry)
return ret;
}
+/**
+ * qdict_clone_shallow(): Clones a given QDict. Its entries are not copied, but
+ * another reference is added.
+ */
+QDict *qdict_clone_shallow(const QDict *src)
+{
+ QDict *dest;
+ QDictEntry *entry;
+ int i;
+
+ dest = qdict_new();
+
+ for (i = 0; i < QDICT_BUCKET_MAX; i++) {
+ QLIST_FOREACH(entry, &src->table[i], next) {
+ qobject_incref(entry->value);
+ qdict_put_obj(dest, entry->key, entry->value);
+ }
+ }
+
+ return dest;
+}
+
/**
* qentry_destroy(): Free all the memory allocated by a QDictEntry
*/

0 comments on commit b382bc9

Please sign in to comment.