[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PULL 15/26] block-qdict: Tweak qdict_flatten_qdict(), qdic
From: |
Kevin Wolf |
Subject: |
[Qemu-devel] [PULL 15/26] block-qdict: Tweak qdict_flatten_qdict(), qdict_flatten_qlist() |
Date: |
Fri, 15 Jun 2018 16:20:57 +0200 |
From: Markus Armbruster <address@hidden>
qdict_flatten_qdict() skips copying scalars from @qdict to @target
when the two are the same. Fair enough, but it uses a non-obvious
test for "same". Replace it by the obvious one. While there, improve
comments.
Signed-off-by: Markus Armbruster <address@hidden>
Reviewed-by: Kevin Wolf <address@hidden>
Signed-off-by: Kevin Wolf <address@hidden>
---
qobject/block-qdict.c | 14 +++++++++-----
1 file changed, 9 insertions(+), 5 deletions(-)
diff --git a/qobject/block-qdict.c b/qobject/block-qdict.c
index f32df343e8..a4e1c8d08f 100644
--- a/qobject/block-qdict.c
+++ b/qobject/block-qdict.c
@@ -71,12 +71,15 @@ static void qdict_flatten_qlist(QList *qlist, QDict
*target, const char *prefix)
value = qlist_entry_obj(entry);
new_key = g_strdup_printf("%s.%i", prefix, i);
+ /*
+ * Flatten non-empty QDict and QList recursively into @target,
+ * copy other objects to @target
+ */
if (qobject_type(value) == QTYPE_QDICT) {
qdict_flatten_qdict(qobject_to(QDict, value), target, new_key);
} else if (qobject_type(value) == QTYPE_QLIST) {
qdict_flatten_qlist(qobject_to(QList, value), target, new_key);
} else {
- /* All other types are moved to the target unchanged. */
qdict_put_obj(target, new_key, qobject_ref(value));
}
@@ -101,9 +104,11 @@ static void qdict_flatten_qdict(QDict *qdict, QDict
*target, const char *prefix)
new_key = g_strdup_printf("%s.%s", prefix, entry->key);
}
+ /*
+ * Flatten non-empty QDict and QList recursively into @target,
+ * copy other objects to @target
+ */
if (qobject_type(value) == QTYPE_QDICT) {
- /* Entries of QDicts are processed recursively, the QDict object
- * itself disappears. */
qdict_flatten_qdict(qobject_to(QDict, value), target,
new_key ? new_key : entry->key);
qdict_del(qdict, entry->key);
@@ -111,8 +116,7 @@ static void qdict_flatten_qdict(QDict *qdict, QDict
*target, const char *prefix)
qdict_flatten_qlist(qobject_to(QList, value), target,
new_key ? new_key : entry->key);
qdict_del(qdict, entry->key);
- } else if (prefix) {
- /* All other objects are moved to the target unchanged. */
+ } else if (target != qdict) {
qdict_put_obj(target, new_key, qobject_ref(value));
qdict_del(qdict, entry->key);
}
--
2.13.6
- [Qemu-devel] [PULL 01/26] qemu-img: Fix assert when mapping unaligned raw file, (continued)
- [Qemu-devel] [PULL 01/26] qemu-img: Fix assert when mapping unaligned raw file, Kevin Wolf, 2018/06/15
- [Qemu-devel] [PULL 03/26] jobs: fix stale wording, Kevin Wolf, 2018/06/15
- [Qemu-devel] [PULL 05/26] rbd: Drop deprecated -drive parameter "filename", Kevin Wolf, 2018/06/15
- [Qemu-devel] [PULL 06/26] iscsi: Drop deprecated -drive parameter "filename", Kevin Wolf, 2018/06/15
- [Qemu-devel] [PULL 02/26] iotests: Add test 221 to catch qemu-img map regression, Kevin Wolf, 2018/06/15
- [Qemu-devel] [PULL 07/26] block: Add block-specific QDict header, Kevin Wolf, 2018/06/15
- [Qemu-devel] [PULL 14/26] block-qdict: Simplify qdict_flatten_qdict(), Kevin Wolf, 2018/06/15
- [Qemu-devel] [PULL 10/26] block: Fix -drive for certain non-string scalars, Kevin Wolf, 2018/06/15
- [Qemu-devel] [PULL 12/26] block: Factor out qobject_input_visitor_new_flat_confused(), Kevin Wolf, 2018/06/15
- [Qemu-devel] [PULL 13/26] block: Make remaining uses of qobject input visitor more robust, Kevin Wolf, 2018/06/15
- [Qemu-devel] [PULL 15/26] block-qdict: Tweak qdict_flatten_qdict(), qdict_flatten_qlist(),
Kevin Wolf <=
- [Qemu-devel] [PULL 17/26] block-qdict: Simplify qdict_is_list() some, Kevin Wolf, 2018/06/15
- [Qemu-devel] [PULL 16/26] block-qdict: Clean up qdict_crumple() a bit, Kevin Wolf, 2018/06/15
- [Qemu-devel] [PULL 09/26] block: Fix -blockdev for certain non-string scalars, Kevin Wolf, 2018/06/15
- [Qemu-devel] [PULL 22/26] rbd: New parameter key-secret, Kevin Wolf, 2018/06/15
- [Qemu-devel] [PULL 20/26] block: Fix -blockdev / blockdev-add for empty objects and arrays, Kevin Wolf, 2018/06/15
- [Qemu-devel] [PULL 18/26] check-block-qdict: Rename qdict_flatten()'s variables for clarity, Kevin Wolf, 2018/06/15
- [Qemu-devel] [PULL 19/26] check-block-qdict: Cover flattening of empty lists and dictionaries, Kevin Wolf, 2018/06/15
- [Qemu-devel] [PULL 21/26] rbd: New parameter auth-client-required, Kevin Wolf, 2018/06/15
- [Qemu-devel] [PULL 11/26] block: Clean up a misuse of qobject_to() in .bdrv_co_create_opts(), Kevin Wolf, 2018/06/15
- [Qemu-devel] [PULL 23/26] block: Remove deprecated -drive geometry options, Kevin Wolf, 2018/06/15