Re: [PATCH] string_list: use string-list API in unsorted_string_list_lookup()
- From
Johannes Schindelin <johannes.schindelin@gmx.de>
- Date
- Apr 24, 2016, 07:06 UTC
- Message-ID
- <alpine.DEB.2.20.1604240901570.2896@virtualbox>
- In-Reply-To
- <20160422173500.32329-1-ralf.thielow@gmail.com>
Hi Ralf,
On Fri, 22 Apr 2016, Ralf Thielow wrote:
Show 7 quoted lines
> Using the string-list API in function unsorted_string_list_lookup() > makes the code more readable. So let's do this. > > Signed-off-by: Ralf Thielow <ralf.thielow@gmail.com> > --- > string-list.c | 9 +++++---- > 1 file changed, 5 insertions(+), 4 deletions(-)
Oh. I hoped for a reduction, not an increase.
Show 20 quoted lines
> diff --git a/string-list.c b/string-list.c
> index 2a32a3f..8127e12 100644
> --- a/string-list.c
> +++ b/string-list.c
> @@ -231,12 +231,13 @@ 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;If you drop the extra curly braces (thereby matching Git's coding style as an additional bonus), at least the patch won't increase the number of lines.
In any case, I like the simplification of the code.
Ciao, Dscho