]> rtime.felk.cvut.cz Git - lisovros/qemu_apohw.git/commitdiff
qdict: Optimise qdict_do_flatten()
authorKevin Wolf <kwolf@redhat.com>
Wed, 20 Nov 2013 12:09:21 +0000 (13:09 +0100)
committerKevin Wolf <kwolf@redhat.com>
Fri, 29 Nov 2013 12:40:37 +0000 (13:40 +0100)
Nested QDicts used to be both entered recursively in order to move their
entries to the target QDict and also be moved themselves to the target
QDict like all other objects. This is harmless because for the top
level, qdict_do_flatten() will encounter the (now empty) QDict for a
second time and then delete it, but at the same time it's obviously
unnecessary overhead. Just delete nested QDicts directly after moving
all of their entries.

Reported-by: Laszlo Ersek <lersek@redhat.com>
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
qobject/qdict.c

index 60d6cd5a0ed0de7b05ef9af93c9c4983fa18a54c..17e14f08b128e81608dc3630279b8972e757bde9 100644 (file)
@@ -494,16 +494,20 @@ static void qdict_do_flatten(QDict *qdict, QDict *target, const char *prefix)
         delete = false;
 
         if (prefix) {
-            qobject_incref(value);
             new_key = g_strdup_printf("%s.%s", prefix, entry->key);
-            qdict_put_obj(target, new_key, value);
-            delete = true;
         }
 
         if (qobject_type(value) == QTYPE_QDICT) {
+            /* Entries of QDicts are processed recursively, the QDict object
+             * itself disappears. */
             qdict_do_flatten(qobject_to_qdict(value), target,
                              new_key ? new_key : entry->key);
             delete = true;
+        } else if (prefix) {
+            /* All other objects are moved to the target unchanged. */
+            qobject_incref(value);
+            qdict_put_obj(target, new_key, value);
+            delete = true;
         }
 
         g_free(new_key);