From: Paolo Bonzini <pbonzini@redhat.com>
To: qemu-devel@nongnu.org
Cc: armbru@redhat.com, eblake@redhat.com
Subject: [Qemu-devel] [PATCH] qapi: change QmpOutputVisitor to QSLIST
Date: Wed, 6 Jul 2016 14:43:36 +0200 [thread overview]
Message-ID: <1467809017-25023-1-git-send-email-pbonzini@redhat.com> (raw)
This saves a little memory compared to the doubly-linked QTAILQ.
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
---
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;
}
--
2.7.4
next reply other threads:[~2016-07-06 12:43 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-07-06 12:43 Paolo Bonzini [this message]
2016-07-06 12:43 ` [Qemu-devel] [PATCH] qapi: change QmpInputVisitor to QSLIST Paolo Bonzini
2016-07-06 15:39 ` Eric Blake
2016-07-07 8:19 ` Markus Armbruster
2016-07-07 11:08 ` Paolo Bonzini
2016-07-07 14:27 ` Markus Armbruster
2016-07-07 11:12 ` Paolo Bonzini
2016-07-07 8:42 ` Markus Armbruster
2016-07-07 14:37 ` Eric Blake
2016-07-06 15:32 ` [Qemu-devel] [PATCH] qapi: change QmpOutputVisitor " Eric Blake
2016-07-07 8:02 ` Markus Armbruster
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=1467809017-25023-1-git-send-email-pbonzini@redhat.com \
--to=pbonzini@redhat.com \
--cc=armbru@redhat.com \
--cc=eblake@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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).