All of lore.kernel.org
 help / color / mirror / Atom feed
From: Markus Armbruster <armbru@redhat.com>
To: qemu-devel@nongnu.org
Cc: Paolo Bonzini <pbonzini@redhat.com>
Subject: [Qemu-devel] [PULL for-2.7 01/15] qapi: change QmpOutputVisitor to QSLIST
Date: Tue, 19 Jul 2016 13:39:23 +0200	[thread overview]
Message-ID: <1468928377-20384-2-git-send-email-armbru@redhat.com> (raw)
In-Reply-To: <1468928377-20384-1-git-send-email-armbru@redhat.com>

From: Paolo Bonzini <pbonzini@redhat.com>

This saves a little memory compared to the doubly-linked QTAILQ.

Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
Message-Id: <1467906798-5312-2-git-send-email-pbonzini@redhat.com>
Reviewed-by: Markus Armbruster <armbru@redhat.com>
Reviewed-by: Eric Blake <eblake@redhat.com>
[Comment tweaked to avoid long line]
Signed-off-by: Markus Armbruster <armbru@redhat.com>
---
 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;
 
-- 
2.5.5

  reply	other threads:[~2016-07-19 11:39 UTC|newest]

Thread overview: 20+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-07-19 11:39 [Qemu-devel] [PULL for-2.7 00/15] QAPI patches for 2016-07-19 Markus Armbruster
2016-07-19 11:39 ` Markus Armbruster [this message]
2016-07-19 11:39 ` [Qemu-devel] [PULL for-2.7 02/15] qapi: change QmpInputVisitor to QSLIST Markus Armbruster
2016-07-19 11:39 ` [Qemu-devel] [PULL for-2.7 03/15] net: use Netdev instead of NetClientOptions in client init Markus Armbruster
2016-07-19 11:39 ` [Qemu-devel] [PULL for-2.7 04/15] qapi: Require all branches of flat union enum to be covered Markus Armbruster
2016-07-19 11:39 ` [Qemu-devel] [PULL for-2.7 05/15] qapi: Special case c_name() for empty type Markus Armbruster
2016-07-19 11:39 ` [Qemu-devel] [PULL for-2.7 06/15] qapi: Hide tag_name data member of variants Markus Armbruster
2016-07-19 11:39 ` [Qemu-devel] [PULL for-2.7 07/15] qapi: Add type.is_empty() helper Markus Armbruster
2016-07-19 11:39 ` [Qemu-devel] [PULL for-2.7 08/15] qapi: Drop useless gen_err_check() Markus Armbruster
2016-07-19 11:39 ` [Qemu-devel] [PULL for-2.7 09/15] qapi-event: Simplify visit of non-implicit data Markus Armbruster
2016-07-19 11:39 ` [Qemu-devel] [PULL for-2.7 10/15] qapi: Plumb in 'boxed' to qapi generator lower levels Markus Armbruster
2016-07-19 11:39 ` [Qemu-devel] [PULL for-2.7 11/15] qapi: Implement boxed types for commands/events Markus Armbruster
2016-07-19 11:39 ` [Qemu-devel] [PULL for-2.7 12/15] block: Simplify block_set_io_throttle Markus Armbruster
2016-07-19 11:39 ` [Qemu-devel] [PULL for-2.7 13/15] block: Simplify drive-mirror Markus Armbruster
2016-07-19 11:39 ` [Qemu-devel] [PULL for-2.7 14/15] qapi: Change Netdev into a flat union Markus Armbruster
2016-07-19 17:22   ` [Qemu-devel] [PATCH 14/15] fixup! " Eric Blake
2016-07-19 11:39 ` [Qemu-devel] [PULL for-2.7 15/15] net: Use correct type for bool flag Markus Armbruster
2016-07-19 16:56 ` [Qemu-devel] [PULL for-2.7 00/15] QAPI patches for 2016-07-19 Peter Maydell
2016-07-19 17:05   ` Eric Blake
2016-07-19 17:06   ` Peter Maydell

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1468928377-20384-2-git-send-email-armbru@redhat.com \
    --to=armbru@redhat.com \
    --cc=pbonzini@redhat.com \
    --cc=qemu-devel@nongnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.