|
|
9ae3a8 |
From 08ab287975f409e420863a8d39e3b3add8ca6088 Mon Sep 17 00:00:00 2001
|
|
|
9ae3a8 |
From: Richard Jones <rjones@redhat.com>
|
|
|
9ae3a8 |
Date: Tue, 2 Jun 2015 09:46:36 +0200
|
|
|
9ae3a8 |
Subject: [PATCH 2/4] qdict: Add qdict_join()
|
|
|
9ae3a8 |
|
|
|
9ae3a8 |
Message-id: <1433238397-2500-2-git-send-email-rjones@redhat.com>
|
|
|
9ae3a8 |
Patchwork-id: 65278
|
|
|
9ae3a8 |
O-Subject: [RHEL-7.2 qemu-kvm PATCH 1/2] qdict: Add qdict_join()
|
|
|
9ae3a8 |
Bugzilla: 1226697
|
|
|
9ae3a8 |
RH-Acked-by: Miroslav Rezanina <mrezanin@redhat.com>
|
|
|
9ae3a8 |
RH-Acked-by: Stefan Hajnoczi <stefanha@redhat.com>
|
|
|
9ae3a8 |
RH-Acked-by: Max Reitz <mreitz@redhat.com>
|
|
|
9ae3a8 |
|
|
|
9ae3a8 |
From: Max Reitz <mreitz@redhat.com>
|
|
|
9ae3a8 |
|
|
|
9ae3a8 |
This function joins two QDicts by absorbing one into the other.
|
|
|
9ae3a8 |
|
|
|
9ae3a8 |
Signed-off-by: Max Reitz <mreitz@redhat.com>
|
|
|
9ae3a8 |
Reviewed-by: Benoit Canet <benoit@irqsave.net>
|
|
|
9ae3a8 |
Reviewed-by: Eric Blake <eblake@redhat.com>
|
|
|
9ae3a8 |
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
|
|
|
9ae3a8 |
Signed-off-by: Miroslav Rezanina <mrezanin@redhat.com>
|
|
|
9ae3a8 |
---
|
|
|
9ae3a8 |
include/qapi/qmp/qdict.h | 3 +++
|
|
|
9ae3a8 |
qobject/qdict.c | 32 ++++++++++++++++++++++++++++++++
|
|
|
9ae3a8 |
2 files changed, 35 insertions(+)
|
|
|
9ae3a8 |
|
|
|
9ae3a8 |
diff --git a/include/qapi/qmp/qdict.h b/include/qapi/qmp/qdict.h
|
|
|
9ae3a8 |
index d6855d1..fc6e2f2 100644
|
|
|
9ae3a8 |
--- a/include/qapi/qmp/qdict.h
|
|
|
9ae3a8 |
+++ b/include/qapi/qmp/qdict.h
|
|
|
9ae3a8 |
@@ -16,6 +16,7 @@
|
|
|
9ae3a8 |
#include "qapi/qmp/qobject.h"
|
|
|
9ae3a8 |
#include "qapi/qmp/qlist.h"
|
|
|
9ae3a8 |
#include "qemu/queue.h"
|
|
|
9ae3a8 |
+#include <stdbool.h>
|
|
|
9ae3a8 |
#include <stdint.h>
|
|
|
9ae3a8 |
|
|
|
9ae3a8 |
#define QDICT_BUCKET_MAX 512
|
|
|
9ae3a8 |
@@ -67,4 +68,6 @@ const char *qdict_get_try_str(const QDict *qdict, const char *key);
|
|
|
9ae3a8 |
QDict *qdict_clone_shallow(const QDict *src);
|
|
|
9ae3a8 |
void qdict_flatten(QDict *qdict);
|
|
|
9ae3a8 |
|
|
|
9ae3a8 |
+void qdict_join(QDict *dest, QDict *src, bool overwrite);
|
|
|
9ae3a8 |
+
|
|
|
9ae3a8 |
#endif /* QDICT_H */
|
|
|
9ae3a8 |
diff --git a/qobject/qdict.c b/qobject/qdict.c
|
|
|
9ae3a8 |
index 472f106..c7e35ae 100644
|
|
|
9ae3a8 |
--- a/qobject/qdict.c
|
|
|
9ae3a8 |
+++ b/qobject/qdict.c
|
|
|
9ae3a8 |
@@ -527,3 +527,35 @@ void qdict_flatten(QDict *qdict)
|
|
|
9ae3a8 |
{
|
|
|
9ae3a8 |
qdict_do_flatten(qdict, qdict, NULL);
|
|
|
9ae3a8 |
}
|
|
|
9ae3a8 |
+
|
|
|
9ae3a8 |
+/**
|
|
|
9ae3a8 |
+ * qdict_join(): Absorb the src QDict into the dest QDict, that is, move all
|
|
|
9ae3a8 |
+ * elements from src to dest.
|
|
|
9ae3a8 |
+ *
|
|
|
9ae3a8 |
+ * If an element from src has a key already present in dest, it will not be
|
|
|
9ae3a8 |
+ * moved unless overwrite is true.
|
|
|
9ae3a8 |
+ *
|
|
|
9ae3a8 |
+ * If overwrite is true, the conflicting values in dest will be discarded and
|
|
|
9ae3a8 |
+ * replaced by the corresponding values from src.
|
|
|
9ae3a8 |
+ *
|
|
|
9ae3a8 |
+ * Therefore, with overwrite being true, the src QDict will always be empty when
|
|
|
9ae3a8 |
+ * this function returns. If overwrite is false, the src QDict will be empty
|
|
|
9ae3a8 |
+ * iff there were no conflicts.
|
|
|
9ae3a8 |
+ */
|
|
|
9ae3a8 |
+void qdict_join(QDict *dest, QDict *src, bool overwrite)
|
|
|
9ae3a8 |
+{
|
|
|
9ae3a8 |
+ const QDictEntry *entry, *next;
|
|
|
9ae3a8 |
+
|
|
|
9ae3a8 |
+ entry = qdict_first(src);
|
|
|
9ae3a8 |
+ while (entry) {
|
|
|
9ae3a8 |
+ next = qdict_next(src, entry);
|
|
|
9ae3a8 |
+
|
|
|
9ae3a8 |
+ if (overwrite || !qdict_haskey(dest, entry->key)) {
|
|
|
9ae3a8 |
+ qobject_incref(entry->value);
|
|
|
9ae3a8 |
+ qdict_put_obj(dest, entry->key, entry->value);
|
|
|
9ae3a8 |
+ qdict_del(src, entry->key);
|
|
|
9ae3a8 |
+ }
|
|
|
9ae3a8 |
+
|
|
|
9ae3a8 |
+ entry = next;
|
|
|
9ae3a8 |
+ }
|
|
|
9ae3a8 |
+}
|
|
|
9ae3a8 |
--
|
|
|
9ae3a8 |
1.8.3.1
|
|
|
9ae3a8 |
|