From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:35375) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Vj6bH-0001gz-0l for qemu-devel@nongnu.org; Wed, 20 Nov 2013 07:09:48 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Vj6bA-0007y5-UK for qemu-devel@nongnu.org; Wed, 20 Nov 2013 07:09:42 -0500 Received: from mx1.redhat.com ([209.132.183.28]:5238) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Vj6bA-0007xz-Kt for qemu-devel@nongnu.org; Wed, 20 Nov 2013 07:09:36 -0500 Received: from int-mx09.intmail.prod.int.phx2.redhat.com (int-mx09.intmail.prod.int.phx2.redhat.com [10.5.11.22]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id rAKC9aTX027275 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Wed, 20 Nov 2013 07:09:36 -0500 From: Kevin Wolf Date: Wed, 20 Nov 2013 13:09:21 +0100 Message-Id: <1384949361-19143-3-git-send-email-kwolf@redhat.com> In-Reply-To: <1384949361-19143-1-git-send-email-kwolf@redhat.com> References: <1384949361-19143-1-git-send-email-kwolf@redhat.com> Subject: [Qemu-devel] [PATCH 2/2] qdict: Optimise qdict_do_flatten() List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: kwolf@redhat.com, lersek@redhat.com, stefanha@redhat.com 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 Signed-off-by: Kevin Wolf --- qobject/qdict.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/qobject/qdict.c b/qobject/qdict.c index 60d6cd5..17e14f0 100644 --- a/qobject/qdict.c +++ b/qobject/qdict.c @@ -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); -- 1.8.1.4