From patchwork Thu Jul 7 15:53:17 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paolo Bonzini X-Patchwork-Id: 9219133 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 0D47160467 for ; Thu, 7 Jul 2016 15:54:00 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id F0EFE280CF for ; Thu, 7 Jul 2016 15:53:59 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id E452E28111; Thu, 7 Jul 2016 15:53:59 +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.8 required=2.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_HI,T_DKIM_INVALID 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 CF980280CF for ; Thu, 7 Jul 2016 15:53:57 +0000 (UTC) Received: from localhost ([::1]:40724 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bLBch-0005bi-RU for patchwork-qemu-devel@patchwork.kernel.org; Thu, 07 Jul 2016 11:53:55 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:41614) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bLBcF-0005Yi-UX for qemu-devel@nongnu.org; Thu, 07 Jul 2016 11:53:28 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1bLBcD-00061E-9Y for qemu-devel@nongnu.org; Thu, 07 Jul 2016 11:53:26 -0400 Received: from mail-wm0-x242.google.com ([2a00:1450:400c:c09::242]:33623) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bLBcC-000612-Ve for qemu-devel@nongnu.org; Thu, 07 Jul 2016 11:53:25 -0400 Received: by mail-wm0-x242.google.com with SMTP id n127so3896681wme.0 for ; Thu, 07 Jul 2016 08:53:24 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references; bh=h2zgxnR60moW1VbjJLuUaJf9d0720Q/B98HtWa4r1zg=; b=ygTKMoqmtq0/Yc/+dMjk1plzqtFa2fBjwbswDSBsPBoHe4h28QtX/QyzrIqNG+6dfn Sp7jnD8YiwwLHOWhBmNMW3dUDCbL4AfZWRC5IUlL2+oDHXcIL7d3f4Y1sCeXGnnufiqZ YBHCUFuTLXbcFEPzqui+8w/gSANG6ePZGHRFIgT2P4BT6lzKgr/koGgNkbljiUpAEvsi XhOCXgMmyzqeJT7newt0KZVd+CBF9uGrZ/5t+0lPgaCgMasSD3TAIEPdap/QbsOdRfFt B7yFU9DK1npOtDOg4nsRWwChpi6z6kAZfjAvduqbja8sCxWbLQklHr/AV385FdLoHxn3 Nbcg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references; bh=h2zgxnR60moW1VbjJLuUaJf9d0720Q/B98HtWa4r1zg=; b=XEVBSTHo4o3i3xxpdqsBWUELWMs0x49S0hVpNHUIEnbKs24Hi6lxnexn6Y+iWi0II7 5SyaYXyO6iCTRRNaXsBJMmV23n6u+fmWTS3GrJJ7F/0LaHMytmZLMqt4edORJKMGTOT9 szpzLnPsQi2f77XWj6nOWMF+ojBzv1obha46b5My0HayBE1iC766+XMZGTWDSWrbpK2+ Of4Bi9RbKM5Yw4ArpvaZkXX75Ak2s7NQO/oQeVDQhusjTr9zP4QaDCPEchp2hI+RR6sP mvhiJP6O3KlHB95ys946cGq1GQv+POWHrrRk0hc6F3NeJzCNilyHZ9ZUJFhyKeK2eQCj VrRA== X-Gm-Message-State: ALyK8tKxe34rf1Yd1MwPA3TMjWwo/yJVHyIHR6Zthv9Z8TezgLKl7h4mW/u1NCF1ObpRsg== X-Received: by 10.28.68.67 with SMTP id r64mr3501114wma.57.1467906804096; Thu, 07 Jul 2016 08:53:24 -0700 (PDT) Received: from donizetti.lan (94-39-188-118.adsl-ull.clienti.tiscali.it. [94.39.188.118]) by smtp.gmail.com with ESMTPSA id r127sm3552032wmf.21.2016.07.07.08.53.22 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 07 Jul 2016 08:53:23 -0700 (PDT) From: Paolo Bonzini To: qemu-devel@nongnu.org Date: Thu, 7 Jul 2016 17:53:17 +0200 Message-Id: <1467906798-5312-2-git-send-email-pbonzini@redhat.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1467906798-5312-1-git-send-email-pbonzini@redhat.com> References: <1467906798-5312-1-git-send-email-pbonzini@redhat.com> X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 2a00:1450:400c:c09::242 Subject: [Qemu-devel] [PATCH v3 1/2] 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 --- 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..64aa42c 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 containers that haven't yet been finished */ 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;