poke-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [PATCH] Remove superfluous malloc from pk_cmd_get_next_match


From: Jose E. Marchesi
Subject: Re: [PATCH] Remove superfluous malloc from pk_cmd_get_next_match
Date: Sun, 12 Apr 2020 15:47:33 +0200
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/28.0.50 (gnu/linux)

    I think this patch is good now.

Then this is OK for master.
Thanks for the review.

Thanks to both of you :)
    
    On Sun, Apr 12, 2020 at 01:50:41PM +0200, Tim R??hsen wrote:
         2020-04-12 Tim R??hsen  <address@hidden>
         
                * src/pk-cmd.c (pk_cmd_get_next_match):
                Remove superfluous malloc within loop.
         ---
          ChangeLog    |  5 +++++
          src/pk-cmd.c | 27 ++++++++++-----------------
          2 files changed, 15 insertions(+), 17 deletions(-)
         
         diff --git a/src/pk-cmd.c b/src/pk-cmd.c
         index f6273586..d4f05fa4 100644
         --- a/src/pk-cmd.c
         +++ b/src/pk-cmd.c
         @@ -775,26 +775,19 @@ pk_cmd_shutdown (void)
          char *
          pk_cmd_get_next_match (int *idx, const char *x, size_t len)
          {
         +  /* X must start with a dot */
         +  if (len == 0 || *x != '.')
         +    return NULL;
         +
            /* Dot commands */
         -  for (;;)
         +  for (const struct pk_cmd **c = dot_cmds + *idx;
         +       *c != &null_cmd;
         +       (*idx)++, c++)
              {
         -      const struct pk_cmd **c = dot_cmds + *idx;
         -      if (*c == &null_cmd)
         -        break;
         -
         -      /* don't forget the null terminator of name */
         -      const size_t name_len = strlen ((*c)->name);
         -      char *name = xmalloc (name_len + 2);
         -      name[0] = '.';
         -      strncpy (name+1, (*c)->name, name_len + 1);
         -      if (0 !=  strncmp (name, x, len))
         -        {
         -          free (name);
         -          (*idx)++;
         -          continue;
         -        }
         -      return name;
         +      if (strncmp ((*c)->name, x + 1, len - 1) == 0)
         +        return pk_str_concat (".", (*c)->name, NULL);
              }
         +
            return NULL;
          }
         
         --
         2.26.0
         
         



reply via email to

[Prev in Thread] Current Thread [Next in Thread]