From: Markus Armbruster <armbru@redhat.com>
To: qemu-devel@nongnu.org
Subject: [Qemu-devel] [PULL for-2.5 08/13] qjson: Inline token_is_escape() and simplify
Date: Thu, 26 Nov 2015 13:47:53 +0100 [thread overview]
Message-ID: <1448542078-11690-9-git-send-email-armbru@redhat.com> (raw)
In-Reply-To: <1448542078-11690-1-git-send-email-armbru@redhat.com>
Signed-off-by: Markus Armbruster <armbru@redhat.com>
Message-Id: <1448486613-17634-8-git-send-email-armbru@redhat.com>
Reviewed-by: Eric Blake <eblake@redhat.com>
---
qobject/json-parser.c | 32 +++++++++++++++-----------------
1 file changed, 15 insertions(+), 17 deletions(-)
diff --git a/qobject/json-parser.c b/qobject/json-parser.c
index df76cc3..b57cac7 100644
--- a/qobject/json-parser.c
+++ b/qobject/json-parser.c
@@ -63,15 +63,6 @@ static JSONTokenType token_get_type(QObject *obj)
return qdict_get_int(qobject_to_qdict(obj), "type");
}
-static int token_is_escape(QObject *obj, const char *value)
-{
- if (token_get_type(obj) != JSON_ESCAPE) {
- return 0;
- }
-
- return (strcmp(token_get_value(obj), value) == 0);
-}
-
/**
* Error handler
*/
@@ -560,6 +551,7 @@ static QObject *parse_escape(JSONParserContext *ctxt, va_list *ap)
{
QObject *token = NULL, *obj;
JSONParserContext saved_ctxt = parser_context_save(ctxt);
+ const char *val;
if (ap == NULL) {
goto out;
@@ -570,20 +562,26 @@ static QObject *parse_escape(JSONParserContext *ctxt, va_list *ap)
goto out;
}
- if (token_is_escape(token, "%p")) {
+ if (token_get_type(token) != JSON_ESCAPE) {
+ goto out;
+ }
+
+ val = token_get_value(token);
+
+ if (!strcmp(val, "%p")) {
obj = va_arg(*ap, QObject *);
- } else if (token_is_escape(token, "%i")) {
+ } else if (!strcmp(val, "%i")) {
obj = QOBJECT(qbool_from_bool(va_arg(*ap, int)));
- } else if (token_is_escape(token, "%d")) {
+ } else if (!strcmp(val, "%d")) {
obj = QOBJECT(qint_from_int(va_arg(*ap, int)));
- } else if (token_is_escape(token, "%ld")) {
+ } else if (!strcmp(val, "%ld")) {
obj = QOBJECT(qint_from_int(va_arg(*ap, long)));
- } else if (token_is_escape(token, "%lld") ||
- token_is_escape(token, "%I64d")) {
+ } else if (!strcmp(val, "%lld") ||
+ !strcmp(val, "%I64d")) {
obj = QOBJECT(qint_from_int(va_arg(*ap, long long)));
- } else if (token_is_escape(token, "%s")) {
+ } else if (!strcmp(val, "%s")) {
obj = QOBJECT(qstring_from_str(va_arg(*ap, const char *)));
- } else if (token_is_escape(token, "%f")) {
+ } else if (!strcmp(val, "%f")) {
obj = QOBJECT(qfloat_from_double(va_arg(*ap, double)));
} else {
goto out;
--
2.4.3
next prev parent reply other threads:[~2015-11-26 12:48 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-11-26 12:47 [Qemu-devel] [PULL for-2.5 00/13] QMP and QObject patches Markus Armbruster
2015-11-26 12:47 ` [Qemu-devel] [PULL for-2.5 01/13] monitor: Plug memory leak on QMP error Markus Armbruster
2015-11-26 12:47 ` [Qemu-devel] [PULL for-2.5 02/13] qjson: Apply nesting limit more sanely Markus Armbruster
2015-11-26 12:47 ` [Qemu-devel] [PULL for-2.5 03/13] qjson: Don't crash when input exceeds nesting limit Markus Armbruster
2015-11-26 12:47 ` [Qemu-devel] [PULL for-2.5 04/13] check-qjson: Add test for JSON nesting depth limit Markus Armbruster
2015-11-26 12:47 ` [Qemu-devel] [PULL for-2.5 05/13] qjson: Spell out some silent assumptions Markus Armbruster
2015-11-26 12:47 ` [Qemu-devel] [PULL for-2.5 06/13] qjson: Give each of the six structural chars its own token type Markus Armbruster
2015-11-26 12:47 ` [Qemu-devel] [PULL for-2.5 07/13] qjson: Inline token_is_keyword() and simplify Markus Armbruster
2015-11-26 12:47 ` Markus Armbruster [this message]
2015-11-26 12:47 ` [Qemu-devel] [PULL for-2.5 09/13] qjson: replace QString in JSONLexer with GString Markus Armbruster
2015-11-26 12:47 ` [Qemu-devel] [PULL for-2.5 10/13] qjson: Convert to parser to recursive descent Markus Armbruster
2015-11-26 12:47 ` [Qemu-devel] [PULL for-2.5 11/13] qjson: store tokens in a GQueue Markus Armbruster
2015-11-26 12:47 ` [Qemu-devel] [PULL for-2.5 12/13] qjson: surprise, allocating 6 QObjects per token is expensive Markus Armbruster
2015-11-26 12:47 ` [Qemu-devel] [PULL for-2.5 13/13] qjson: Limit number of tokens in addition to total size Markus Armbruster
2015-11-26 16:50 ` [Qemu-devel] [PULL for-2.5 00/13] QMP and QObject patches 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=1448542078-11690-9-git-send-email-armbru@redhat.com \
--to=armbru@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).