From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:45230) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1b3FmP-0002nH-6F for qemu-devel@nongnu.org; Thu, 19 May 2016 00:41:56 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1b3FmI-000599-1j for qemu-devel@nongnu.org; Thu, 19 May 2016 00:41:48 -0400 Received: from mx1.redhat.com ([209.132.183.28]:56149) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1b3FmH-000590-PS for qemu-devel@nongnu.org; Thu, 19 May 2016 00:41:41 -0400 Received: from int-mx09.intmail.prod.int.phx2.redhat.com (int-mx09.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 5EAA964D28 for ; Thu, 19 May 2016 04:41:41 +0000 (UTC) From: Eric Blake Date: Wed, 18 May 2016 22:41:05 -0600 Message-Id: <1463632874-28559-20-git-send-email-eblake@redhat.com> In-Reply-To: <1463632874-28559-1-git-send-email-eblake@redhat.com> References: <1463632874-28559-1-git-send-email-eblake@redhat.com> Subject: [Qemu-devel] [PATCH v4 19/28] qapi: Use qstring_append_chr() where appropriate List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: armbru@redhat.com, Luiz Capitulino qstring_append_chr() is more efficient than qstring_append() when dealing with a one-byte string (including the case of a temporary 2-byte buffer just for creating a dynamic one-byte string). Signed-off-by: Eric Blake --- v4: also convert qstring_append() of one-byte strings v3: no change v2: no change --- qobject/json-parser.c | 25 ++++++++++--------------- qobject/qobject-json.c | 12 ++++++------ 2 files changed, 16 insertions(+), 21 deletions(-) diff --git a/qobject/json-parser.c b/qobject/json-parser.c index c18e48a..5c23740 100644 --- a/qobject/json-parser.c +++ b/qobject/json-parser.c @@ -143,39 +143,39 @@ static QString *qstring_from_escaped_str(JSONParserContext *ctxt, switch (*ptr) { case '"': - qstring_append(str, "\""); + qstring_append_chr(str, '"'); ptr++; break; case '\'': - qstring_append(str, "'"); + qstring_append_chr(str, '\''); ptr++; break; case '\\': - qstring_append(str, "\\"); + qstring_append_chr(str, '\\'); ptr++; break; case '/': - qstring_append(str, "/"); + qstring_append_chr(str, '/'); ptr++; break; case 'b': - qstring_append(str, "\b"); + qstring_append_chr(str, '\b'); ptr++; break; case 'f': - qstring_append(str, "\f"); + qstring_append_chr(str, '\f'); ptr++; break; case 'n': - qstring_append(str, "\n"); + qstring_append_chr(str, '\n'); ptr++; break; case 'r': - qstring_append(str, "\r"); + qstring_append_chr(str, '\r'); ptr++; break; case 't': - qstring_append(str, "\t"); + qstring_append_chr(str, '\t'); ptr++; break; case 'u': { @@ -204,12 +204,7 @@ static QString *qstring_from_escaped_str(JSONParserContext *ctxt, goto out; } } else { - char dummy[2]; - - dummy[0] = *ptr++; - dummy[1] = 0; - - qstring_append(str, dummy); + qstring_append_chr(str, *ptr++); } } diff --git a/qobject/qobject-json.c b/qobject/qobject-json.c index 769816d..95de587 100644 --- a/qobject/qobject-json.c +++ b/qobject/qobject-json.c @@ -140,12 +140,12 @@ static void to_json(const QObject *obj, QString *str, int pretty, int indent) s.str = str; s.indent = indent + 1; s.pretty = pretty; - qstring_append(str, "{"); + qstring_append_chr(str, '{'); qdict_iter(val, to_json_dict_iter, &s); if (pretty) { qstring_append_printf(str, "\n%*s", 4 * indent, ""); } - qstring_append(str, "}"); + qstring_append_chr(str, '}'); break; } case QTYPE_QLIST: { @@ -156,12 +156,12 @@ static void to_json(const QObject *obj, QString *str, int pretty, int indent) s.str = str; s.indent = indent + 1; s.pretty = pretty; - qstring_append(str, "["); + qstring_append_chr(str, '['); qlist_iter(val, (void *)to_json_list_iter, &s); if (pretty) { qstring_append_printf(str, "\n%*s", 4 * indent, ""); } - qstring_append(str, "]"); + qstring_append_chr(str, ']'); break; } case QTYPE_QFLOAT: { @@ -217,7 +217,7 @@ int qstring_append_json_string(QString *qstring, const char *str) char *end; int result = 0; - qstring_append(qstring, "\""); + qstring_append_chr(qstring, '"'); for (ptr = str; *ptr; ptr = end) { cp = mod_utf8_codepoint(ptr, 6, &end); @@ -261,7 +261,7 @@ int qstring_append_json_string(QString *qstring, const char *str) } }; - qstring_append(qstring, "\""); + qstring_append_chr(qstring, '"'); return result; } -- 2.5.5