diff mbox

[v3,05/18] qapi: Use qstring_append_chr() where appropriate

Message ID 1461903820-3092-6-git-send-email-eblake@redhat.com (mailing list archive)
State New, archived
Headers show

Commit Message

Eric Blake April 29, 2016, 4:23 a.m. UTC
No need to create a temporary buffer, when we already have a
function available for our needs.

Signed-off-by: Eric Blake <eblake@redhat.com>
Reviewed-by: Fam Zheng <famz@redhat.com>

---
v3: no change
v2: no change
---
 qobject/json-parser.c | 7 +------
 1 file changed, 1 insertion(+), 6 deletions(-)

Comments

Markus Armbruster April 29, 2016, 1:25 p.m. UTC | #1
Eric Blake <eblake@redhat.com> writes:

> No need to create a temporary buffer, when we already have a
> function available for our needs.
>
> Signed-off-by: Eric Blake <eblake@redhat.com>
> Reviewed-by: Fam Zheng <famz@redhat.com>
>
> ---
> v3: no change
> v2: no change
> ---
>  qobject/json-parser.c | 7 +------
>  1 file changed, 1 insertion(+), 6 deletions(-)
>
> diff --git a/qobject/json-parser.c b/qobject/json-parser.c
> index c18e48a..5fbaf58 100644
> --- a/qobject/json-parser.c
> +++ b/qobject/json-parser.c
> @@ -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++);
>          }
>      }

The function has several qstring_append(str, S) where S consists of a
single character.  They could all be converted to qstring_append_chr().
diff mbox

Patch

diff --git a/qobject/json-parser.c b/qobject/json-parser.c
index c18e48a..5fbaf58 100644
--- a/qobject/json-parser.c
+++ b/qobject/json-parser.c
@@ -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++);
         }
     }