From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:40227) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1a1hXP-000511-CP for qemu-devel@nongnu.org; Wed, 25 Nov 2015 16:23:40 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1a1hXO-0000XN-42 for qemu-devel@nongnu.org; Wed, 25 Nov 2015 16:23:39 -0500 Received: from mx1.redhat.com ([209.132.183.28]:40495) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1a1hXN-0000XH-V6 for qemu-devel@nongnu.org; Wed, 25 Nov 2015 16:23:38 -0500 Received: from int-mx11.intmail.prod.int.phx2.redhat.com (int-mx11.intmail.prod.int.phx2.redhat.com [10.5.11.24]) by mx1.redhat.com (Postfix) with ESMTPS id 9C2C625891 for ; Wed, 25 Nov 2015 21:23:37 +0000 (UTC) From: Markus Armbruster Date: Wed, 25 Nov 2015 22:23:27 +0100 Message-Id: <1448486613-17634-7-git-send-email-armbru@redhat.com> In-Reply-To: <1448486613-17634-1-git-send-email-armbru@redhat.com> References: <1448486613-17634-1-git-send-email-armbru@redhat.com> Subject: [Qemu-devel] [PATCH v3 for-2.5 06/12] qjson: Inline token_is_keyword() and simplify List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: pbonzini@redhat.com, lcapitulino@redhat.com Signed-off-by: Markus Armbruster --- qobject/json-parser.c | 20 +++++++------------- 1 file changed, 7 insertions(+), 13 deletions(-) diff --git a/qobject/json-parser.c b/qobject/json-parser.c index 020c6e1..df76cc3 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_keyword(QObject *obj, const char *value) -{ - if (token_get_type(obj) != JSON_KEYWORD) { - return 0; - } - - return strcmp(token_get_value(obj), value) == 0; -} - static int token_is_escape(QObject *obj, const char *value) { if (token_get_type(obj) != JSON_ESCAPE) { @@ -533,6 +524,7 @@ static QObject *parse_keyword(JSONParserContext *ctxt) { QObject *token, *ret; JSONParserContext saved_ctxt = parser_context_save(ctxt); + const char *val; token = parser_context_pop_token(ctxt); if (token == NULL) { @@ -543,14 +535,16 @@ static QObject *parse_keyword(JSONParserContext *ctxt) goto out; } - if (token_is_keyword(token, "true")) { + val = token_get_value(token); + + if (!strcmp(val, "true")) { ret = QOBJECT(qbool_from_bool(true)); - } else if (token_is_keyword(token, "false")) { + } else if (!strcmp(val, "false")) { ret = QOBJECT(qbool_from_bool(false)); - } else if (token_is_keyword(token, "null")) { + } else if (!strcmp(val, "null")) { ret = qnull(); } else { - parse_error(ctxt, token, "invalid keyword `%s'", token_get_value(token)); + parse_error(ctxt, token, "invalid keyword '%s'", val); goto out; } -- 2.4.3