From patchwork Wed Jul 6 12:43:36 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paolo Bonzini X-Patchwork-Id: 9216311 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id EE1F860467 for ; Wed, 6 Jul 2016 12:44:08 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id DFCB32889A for ; Wed, 6 Jul 2016 12:44:08 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id D35522889C; Wed, 6 Jul 2016 12:44:08 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.9 required=2.0 tests=BAYES_00,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 7C8942889A for ; Wed, 6 Jul 2016 12:44:08 +0000 (UTC) Received: from localhost ([::1]:33370 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bKmBT-0006fj-PU for patchwork-qemu-devel@patchwork.kernel.org; Wed, 06 Jul 2016 08:44:07 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:40794) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bKmB7-0006eG-72 for qemu-devel@nongnu.org; Wed, 06 Jul 2016 08:43:46 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1bKmB2-00016b-UR for qemu-devel@nongnu.org; Wed, 06 Jul 2016 08:43:44 -0400 Received: from mx1.redhat.com ([209.132.183.28]:36808) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bKmB2-00016X-Of for qemu-devel@nongnu.org; Wed, 06 Jul 2016 08:43:40 -0400 Received: from int-mx10.intmail.prod.int.phx2.redhat.com (int-mx10.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 52F46201E9 for ; Wed, 6 Jul 2016 12:43:40 +0000 (UTC) Received: from donizetti.redhat.com (ovpn-112-48.ams2.redhat.com [10.36.112.48]) by int-mx10.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id u66Chc7l031276; Wed, 6 Jul 2016 08:43:38 -0400 From: Paolo Bonzini To: qemu-devel@nongnu.org Date: Wed, 6 Jul 2016 14:43:36 +0200 Message-Id: <1467809017-25023-1-git-send-email-pbonzini@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.23 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.29]); Wed, 06 Jul 2016 12:43:40 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH] qapi: change QmpOutputVisitor to QSLIST X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: armbru@redhat.com Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP This saves a little memory compared to the doubly-linked QTAILQ. Signed-off-by: Paolo Bonzini Reviewed-by: Eric Blake Reviewed-by: Markus Armbruster --- qapi/qmp-output-visitor.c | 25 +++++++++---------------- 1 file changed, 9 insertions(+), 16 deletions(-) diff --git a/qapi/qmp-output-visitor.c b/qapi/qmp-output-visitor.c index 4d3cf78..676df1f 100644 --- a/qapi/qmp-output-visitor.c +++ b/qapi/qmp-output-visitor.c @@ -22,15 +22,13 @@ typedef struct QStackEntry { QObject *value; - QTAILQ_ENTRY(QStackEntry) node; + QSLIST_ENTRY(QStackEntry) node; } QStackEntry; -typedef QTAILQ_HEAD(QStack, QStackEntry) QStack; - struct QmpOutputVisitor { Visitor visitor; - QStack stack; /* Stack of containers that haven't yet been finished */ + QSLIST_HEAD(, QStackEntry) stack; /* Stack of containers that haven't yet been finished */ QObject *root; /* Root of the output visit */ }; @@ -51,17 +49,17 @@ static void qmp_output_push_obj(QmpOutputVisitor *qov, QObject *value) assert(qov->root); assert(value); e->value = value; - QTAILQ_INSERT_HEAD(&qov->stack, e, node); + QSLIST_INSERT_HEAD(&qov->stack, e, node); } /* Pop a value off the stack of QObjects being built, and return it. */ static QObject *qmp_output_pop(QmpOutputVisitor *qov) { - QStackEntry *e = QTAILQ_FIRST(&qov->stack); + QStackEntry *e = QSLIST_FIRST(&qov->stack); QObject *value; assert(e); - QTAILQ_REMOVE(&qov->stack, e, node); + QSLIST_REMOVE_HEAD(&qov->stack, node); value = e->value; assert(value); g_free(e); @@ -74,7 +72,7 @@ static QObject *qmp_output_pop(QmpOutputVisitor *qov) static void qmp_output_add_obj(QmpOutputVisitor *qov, const char *name, QObject *value) { - QStackEntry *e = QTAILQ_FIRST(&qov->stack); + QStackEntry *e = QSLIST_FIRST(&qov->stack); QObject *cur = e ? e->value : NULL; if (!cur) { @@ -198,7 +196,7 @@ static void qmp_output_type_null(Visitor *v, const char *name, Error **errp) QObject *qmp_output_get_qobject(QmpOutputVisitor *qov) { /* A visit must have occurred, with each start paired with end. */ - assert(qov->root && QTAILQ_EMPTY(&qov->stack)); + assert(qov->root && QSLIST_EMPTY(&qov->stack)); qobject_incref(qov->root); return qov->root; @@ -211,11 +209,8 @@ Visitor *qmp_output_get_visitor(QmpOutputVisitor *v) void qmp_output_visitor_cleanup(QmpOutputVisitor *v) { - QStackEntry *e, *tmp; - - QTAILQ_FOREACH_SAFE(e, &v->stack, node, tmp) { - QTAILQ_REMOVE(&v->stack, e, node); - g_free(e); + while (!QSLIST_EMPTY(&v->stack)) { + qmp_output_pop(v); } qobject_decref(v->root); @@ -242,7 +237,5 @@ QmpOutputVisitor *qmp_output_visitor_new(void) v->visitor.type_any = qmp_output_type_any; v->visitor.type_null = qmp_output_type_null; - QTAILQ_INIT(&v->stack); - return v; }