From patchwork Tue Jul 19 11:39:23 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Markus Armbruster X-Patchwork-Id: 9236815 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 06CAA60574 for ; Tue, 19 Jul 2016 11:40:24 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id EB88720265 for ; Tue, 19 Jul 2016 11:40:23 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id DE4A326247; Tue, 19 Jul 2016 11:40:23 +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 49B0F20265 for ; Tue, 19 Jul 2016 11:40:23 +0000 (UTC) Received: from localhost ([::1]:54819 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bPTNu-0001cK-5A for patchwork-qemu-devel@patchwork.kernel.org; Tue, 19 Jul 2016 07:40:22 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:50887) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bPTNJ-0001Z9-O9 for qemu-devel@nongnu.org; Tue, 19 Jul 2016 07:39:47 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1bPTNG-0001u8-5X for qemu-devel@nongnu.org; Tue, 19 Jul 2016 07:39:44 -0400 Received: from mx1.redhat.com ([209.132.183.28]:55414) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bPTNF-0001tq-Ty for qemu-devel@nongnu.org; Tue, 19 Jul 2016 07:39:42 -0400 Received: from int-mx14.intmail.prod.int.phx2.redhat.com (int-mx14.intmail.prod.int.phx2.redhat.com [10.5.11.27]) (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 C0D3EC00331B for ; Tue, 19 Jul 2016 11:39:40 +0000 (UTC) Received: from blackfin.pond.sub.org (ovpn-116-35.ams2.redhat.com [10.36.116.35]) by int-mx14.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id u6JBdc9t000740 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NO); Tue, 19 Jul 2016 07:39:39 -0400 Received: by blackfin.pond.sub.org (Postfix, from userid 1000) id 017A711AD28D; Tue, 19 Jul 2016 13:39:38 +0200 (CEST) From: Markus Armbruster To: qemu-devel@nongnu.org Date: Tue, 19 Jul 2016 13:39:23 +0200 Message-Id: <1468928377-20384-2-git-send-email-armbru@redhat.com> In-Reply-To: <1468928377-20384-1-git-send-email-armbru@redhat.com> References: <1468928377-20384-1-git-send-email-armbru@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.27 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.31]); Tue, 19 Jul 2016 11:39:41 +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] [PULL for-2.7 01/15] 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: Paolo Bonzini Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP From: Paolo Bonzini This saves a little memory compared to the doubly-linked QTAILQ. Signed-off-by: Paolo Bonzini Message-Id: <1467906798-5312-2-git-send-email-pbonzini@redhat.com> Reviewed-by: Markus Armbruster Reviewed-by: Eric Blake [Comment tweaked to avoid long line] Signed-off-by: Markus Armbruster --- qapi/qmp-output-visitor.c | 24 +++++++++++------------- 1 file changed, 11 insertions(+), 13 deletions(-) diff --git a/qapi/qmp-output-visitor.c b/qapi/qmp-output-visitor.c index 0452056..9e3b67c 100644 --- a/qapi/qmp-output-visitor.c +++ b/qapi/qmp-output-visitor.c @@ -23,15 +23,13 @@ typedef struct QStackEntry { QObject *value; void *qapi; /* sanity check that caller uses same pointer */ - 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 unfinished containers */ QObject *root; /* Root of the output visit */ QObject **result; /* User's storage location for result */ }; @@ -56,18 +54,18 @@ static void qmp_output_push_obj(QmpOutputVisitor *qov, QObject *value, assert(value); e->value = value; e->qapi = qapi; - 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, void *qapi) { - QStackEntry *e = QTAILQ_FIRST(&qov->stack); + QStackEntry *e = QSLIST_FIRST(&qov->stack); QObject *value; assert(e); assert(e->qapi == qapi); - QTAILQ_REMOVE(&qov->stack, e, node); + QSLIST_REMOVE_HEAD(&qov->stack, node); value = e->value; assert(value); g_free(e); @@ -80,7 +78,7 @@ static QObject *qmp_output_pop(QmpOutputVisitor *qov, void *qapi) 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) { @@ -206,7 +204,7 @@ static void qmp_output_complete(Visitor *v, void *opaque) QmpOutputVisitor *qov = to_qov(v); /* 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)); assert(opaque == qov->result); qobject_incref(qov->root); @@ -217,10 +215,11 @@ static void qmp_output_complete(Visitor *v, void *opaque) static void qmp_output_free(Visitor *v) { QmpOutputVisitor *qov = to_qov(v); - QStackEntry *e, *tmp; + QStackEntry *e; - QTAILQ_FOREACH_SAFE(e, &qov->stack, node, tmp) { - QTAILQ_REMOVE(&qov->stack, e, node); + while (!QSLIST_EMPTY(&qov->stack)) { + e = QSLIST_FIRST(&qov->stack); + QSLIST_REMOVE_HEAD(&qov->stack, node); g_free(e); } @@ -250,7 +249,6 @@ Visitor *qmp_output_visitor_new(QObject **result) v->visitor.complete = qmp_output_complete; v->visitor.free = qmp_output_free; - QTAILQ_INIT(&v->stack); *result = NULL; v->result = result;