From: Johannes Schindelin <Johannes.Schindelin@gmx.de>
To: Ralf Thielow <ralf.thielow@gmail.com>
Cc: git@vger.kernel.org
Subject: Re: [PATCH] string_list: use string-list API in unsorted_string_list_lookup()
Date: Sun, 24 Apr 2016 09:06:12 +0200 (CEST) [thread overview]
Message-ID: <alpine.DEB.2.20.1604240901570.2896@virtualbox> (raw)
In-Reply-To: <20160422173500.32329-1-ralf.thielow@gmail.com>
Hi Ralf,
On Fri, 22 Apr 2016, Ralf Thielow wrote:
> 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.
> 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
next prev parent reply other threads:[~2016-04-24 7:06 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-04-22 17:35 [PATCH] string_list: use string-list API in unsorted_string_list_lookup() Ralf Thielow
2016-04-24 7:06 ` Johannes Schindelin [this message]
2016-04-25 17:35 ` Ralf Thielow
2016-04-25 17:40 ` [PATCH v2] " Ralf Thielow
2016-04-25 17:47 ` Stefan Beller
2016-04-26 15:42 ` Johannes Schindelin
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=alpine.DEB.2.20.1604240901570.2896@virtualbox \
--to=johannes.schindelin@gmx.de \
--cc=git@vger.kernel.org \
--cc=ralf.thielow@gmail.com \
/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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox