git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: [PATCH v2] string_list: use string-list API in unsorted_string_list_lookup()

From
Stefan Beller <sbeller@google.com>
Date
Apr 25, 2016, 17:47 UTC
Message-ID
<CAGZ79kbjtcnRmKPz-vP3C38hsjD3OauAvqctCmhhhfy7g4WDFQ@mail.gmail.com>
In-Reply-To
<20160425174000.24943-1-ralf.thielow@gmail.com>
On Mon, Apr 25, 2016 at 10:40 AM, Ralf Thielow <ralf.thielow@gmail.com> wrote:
Show 7 quoted lines
> Using the string-list API in function unsorted_string_list_lookup()
> makes the code more readable.
>
> Signed-off-by: Ralf Thielow <ralf.thielow@gmail.com>
> ---
> Changes since v1:
> - remove extra curly braces
Reviewed-by: Stefan Beller <sbeller@google.com>
Show 28 quoted lines
>
>  string-list.c | 8 ++++----
>  1 file changed, 4 insertions(+), 4 deletions(-)
>
> diff --git a/string-list.c b/string-list.c
> index 2a32a3f..62d2084 100644
> --- a/string-list.c
> +++ b/string-list.c
> @@ -231,12 +231,12 @@ void string_list_sort(struct string_list *list)
>  struct string_list_item *unsorted_string_list_lookup(struct string_list *list,
>                                                      const char *string)
>  {
> -       int i;
> +       struct string_list_item *item;
>         compare_strings_fn cmp = list->cmp ? list->cmp : strcmp;
>
> -       for (i = 0; i < list->nr; i++)
> -               if (!cmp(string, list->items[i].string))
> -                       return list->items + i;
> +       for_each_string_list_item(item, list)
> +               if (!cmp(string, item->string))
> +                       return item;
>         return NULL;
>  }
>
> --
> 2.8.1.430.g7c694c5
>
Previous: Ralf ThielowNext: Johannes Schindelin
Message 5 of 6 in “string_list: use string-list API in unsorted_string_list_lookup()”
  1. string_list: use string-list API in unsorted_string_list_lookup()Ralf Thielow, Apr 22, 2016
  2. Johannes SchindelinApr 24, 2016
  3. Ralf ThielowApr 25, 2016
  4. string_list: use string-list API in unsorted_string_list_lookup()Ralf Thielow, Apr 25, 2016
  5. Stefan BellerApr 25, 2016
  6. Johannes SchindelinApr 26, 2016

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.