All of lore.kernel.org
 help / color / mirror / Atom feed
From: Markus Armbruster <armbru@redhat.com>
To: Paolo Bonzini <pbonzini@redhat.com>
Cc: qemu-devel@nongnu.org
Subject: Re: [PATCH v2 1/6] qemu-option: simplify search for end of key
Date: Mon, 09 Nov 2020 15:48:30 +0100	[thread overview]
Message-ID: <878sba7fi9.fsf@dusky.pond.sub.org> (raw)
In-Reply-To: <20201109133931.979563-2-pbonzini@redhat.com> (Paolo Bonzini's message of "Mon, 9 Nov 2020 08:39:26 -0500")

Paolo Bonzini <pbonzini@redhat.com> writes:

> Use strcspn to find an equal or comma value, and pass the result directly
> to get_opt_name to avoid another strchr.
>
> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
> ---
>  util/qemu-option.c | 35 +++++++++++++----------------------
>  1 file changed, 13 insertions(+), 22 deletions(-)
>
> diff --git a/util/qemu-option.c b/util/qemu-option.c
> index acefbc23fa..ab3b58599e 100644
> --- a/util/qemu-option.c
> +++ b/util/qemu-option.c
> @@ -38,27 +38,19 @@
>  #include "qemu/help_option.h"
>  
>  /*
> - * Extracts the name of an option from the parameter string (p points at the
> + * Extracts the name of an option from the parameter string (@p points at the
>   * first byte of the option name)
>   *
> - * The option name is delimited by delim (usually , or =) or the string end
> - * and is copied into option. The caller is responsible for free'ing option
> - * when no longer required.
> + * The option name is @len characters long and is copied into @option. The
> + * caller is responsible for free'ing @option when no longer required.
>   *
>   * The return value is the position of the delimiter/zero byte after the option
> - * name in p.
> + * name in @p.
>   */
> -static const char *get_opt_name(const char *p, char **option, char delim)
> +static const char *get_opt_name(const char *p, char **option, size_t len)
>  {
> -    char *offset = strchr(p, delim);
> -
> -    if (offset) {
> -        *option = g_strndup(p, offset - p);
> -        return offset;
> -    } else {
> -        *option = g_strdup(p);
> -        return p + strlen(p);
> -    }
> +    *option = g_strndup(p, len);
> +    return p + len;
>  }

Hardly anything left; I believe this can be simplified further.  Not a
reason to delay this series.

>  
>  /*
> @@ -769,12 +761,11 @@ static const char *get_opt_name_value(const char *params,
>                                        const char *firstname,
>                                        char **name, char **value)
>  {
> -    const char *p, *pe, *pc;
> -
> -    pe = strchr(params, '=');
> -    pc = strchr(params, ',');
> +    const char *p;
> +    size_t len;
>  
> -    if (!pe || (pc && pc < pe)) {
> +    len = strcspn(params, "=,");
> +    if (params[len] != '=') {
>          /* found "foo,more" */
>          if (firstname) {
>              /* implicitly named first option */
> @@ -782,7 +773,7 @@ static const char *get_opt_name_value(const char *params,
>              p = get_opt_value(params, value);
>          } else {
>              /* option without value, must be a flag */
> -            p = get_opt_name(params, name, ',');
> +            p = get_opt_name(params, name, len);
>              if (strncmp(*name, "no", 2) == 0) {
>                  memmove(*name, *name + 2, strlen(*name + 2) + 1);
>                  *value = g_strdup("off");
> @@ -792,7 +783,7 @@ static const char *get_opt_name_value(const char *params,
>          }
>      } else {
>          /* found "foo=bar,more" */
> -        p = get_opt_name(params, name, '=');
> +        p = get_opt_name(params, name, len);
>          assert(*p == '=');
>          p++;
>          p = get_opt_value(p, value);

Reviewed-by: Markus Armbruster <armbru@redhat.com>



  reply	other threads:[~2020-11-09 14:50 UTC|newest]

Thread overview: 26+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-11-09 13:39 [PATCH v2 for-5.2 0/6] Deprecate or forbid crazy QemuOpts cases Paolo Bonzini
2020-11-09 13:39 ` [PATCH v2 1/6] qemu-option: simplify search for end of key Paolo Bonzini
2020-11-09 14:48   ` Markus Armbruster [this message]
2020-11-09 13:39 ` [PATCH v2 2/6] qemu-option: pass QemuOptsList to opts_accepts_any Paolo Bonzini
2020-11-09 15:27   ` Markus Armbruster
2020-11-09 13:39 ` [PATCH v2 3/6] qemu-option: restrict qemu_opts_set to merge-lists QemuOpts Paolo Bonzini
2020-11-09 15:55   ` Markus Armbruster
2020-11-09 16:21     ` Paolo Bonzini
2020-11-09 18:52       ` Markus Armbruster
2020-11-09 18:58         ` Paolo Bonzini
2020-11-09 13:39 ` [PATCH v2 4/6] qemu-option: clean up id vs. list->merge_lists Paolo Bonzini
2020-11-09 16:56   ` Markus Armbruster
2020-11-09 17:17     ` Paolo Bonzini
2020-11-09 18:38       ` Markus Armbruster
2020-11-09 18:59         ` Paolo Bonzini
2020-11-10  8:29           ` Markus Armbruster
2020-11-10  8:39             ` Paolo Bonzini
2020-11-10  9:54               ` Markus Armbruster
2020-11-09 13:39 ` [PATCH v2 5/6] qemu-option: move help handling to get_opt_name_value Paolo Bonzini
2020-11-09 19:40   ` Markus Armbruster
2020-11-09 19:47     ` Paolo Bonzini
2020-11-09 13:39 ` [PATCH v2 6/6] qemu-option: warn for short-form boolean options Paolo Bonzini
2020-11-09 21:19   ` Markus Armbruster
2020-11-09 21:42     ` Paolo Bonzini
2020-11-10  8:32       ` Markus Armbruster
2020-11-09 13:54 ` [PATCH v2 for-5.2 0/6] Deprecate or forbid crazy QemuOpts cases no-reply

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=878sba7fi9.fsf@dusky.pond.sub.org \
    --to=armbru@redhat.com \
    --cc=pbonzini@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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.