From d2ca7c0b0d876cf0e219ae7a92252626b0913a28 Mon Sep 17 00:00:00 2001 From: Paolo Bonzini Date: Wed, 25 Nov 2015 22:23:29 +0100 Subject: qjson: replace QString in JSONLexer with GString JSONLexer only needs a simple resizable buffer. json-streamer.c can allocate memory for each token instead of relying on reference counting of QStrings. Signed-off-by: Paolo Bonzini Message-Id: <1448300659-23559-2-git-send-email-pbonzini@redhat.com> [Straightforwardly rebased on my patches, checkpatch made happy] Signed-off-by: Markus Armbruster Reviewed-by: Eric Blake --- qobject/json-streamer.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) (limited to 'qobject/json-streamer.c') diff --git a/qobject/json-streamer.c b/qobject/json-streamer.c index 4a161a17a1..7292f3a38f 100644 --- a/qobject/json-streamer.c +++ b/qobject/json-streamer.c @@ -12,6 +12,7 @@ */ #include "qapi/qmp/qlist.h" +#include "qapi/qmp/qstring.h" #include "qapi/qmp/qint.h" #include "qapi/qmp/qdict.h" #include "qemu-common.h" @@ -21,7 +22,8 @@ #define MAX_TOKEN_SIZE (64ULL << 20) #define MAX_NESTING (1ULL << 10) -static void json_message_process_token(JSONLexer *lexer, QString *token, JSONTokenType type, int x, int y) +static void json_message_process_token(JSONLexer *lexer, GString *input, + JSONTokenType type, int x, int y) { JSONMessageParser *parser = container_of(lexer, JSONMessageParser, lexer); QDict *dict; @@ -45,12 +47,11 @@ static void json_message_process_token(JSONLexer *lexer, QString *token, JSONTok dict = qdict_new(); qdict_put(dict, "type", qint_from_int(type)); - QINCREF(token); - qdict_put(dict, "token", token); + qdict_put(dict, "token", qstring_from_str(input->str)); qdict_put(dict, "x", qint_from_int(x)); qdict_put(dict, "y", qint_from_int(y)); - parser->token_size += token->length; + parser->token_size += input->len; qlist_append(parser->tokens, dict); -- cgit v1.2.3-55-g7522