* [PATCH] string_list: use string-list API in unsorted_string_list_lookup()
@ 2016-04-22 17:35 Ralf Thielow
2016-04-24 7:06 ` Johannes Schindelin
2016-04-25 17:40 ` [PATCH v2] " Ralf Thielow
0 siblings, 2 replies; 6+ messages in thread
From: Ralf Thielow @ 2016-04-22 17:35 UTC (permalink / raw)
To: git; +Cc: Ralf Thielow
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(-)
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;
}
--
2.8.1.382.g1352ede
^ permalink raw reply related [flat|nested] 6+ messages in thread
* Re: [PATCH] string_list: use string-list API in unsorted_string_list_lookup()
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
2016-04-25 17:35 ` Ralf Thielow
2016-04-25 17:40 ` [PATCH v2] " Ralf Thielow
1 sibling, 1 reply; 6+ messages in thread
From: Johannes Schindelin @ 2016-04-24 7:06 UTC (permalink / raw)
To: Ralf Thielow; +Cc: git
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
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH] string_list: use string-list API in unsorted_string_list_lookup()
2016-04-24 7:06 ` Johannes Schindelin
@ 2016-04-25 17:35 ` Ralf Thielow
0 siblings, 0 replies; 6+ messages in thread
From: Ralf Thielow @ 2016-04-25 17:35 UTC (permalink / raw)
To: Johannes Schindelin; +Cc: git
Johannes Schindelin <Johannes.Schindelin@gmx.de> writes:
>>
>> - 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.
>
Oops. I'll send a new version of the patch without these
extra curly braces.
Thanks!
> In any case, I like the simplification of the code.
>
> Ciao,
> Dscho
^ permalink raw reply [flat|nested] 6+ messages in thread
* [PATCH v2] string_list: use string-list API in unsorted_string_list_lookup()
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
@ 2016-04-25 17:40 ` Ralf Thielow
2016-04-25 17:47 ` Stefan Beller
2016-04-26 15:42 ` Johannes Schindelin
1 sibling, 2 replies; 6+ messages in thread
From: Ralf Thielow @ 2016-04-25 17:40 UTC (permalink / raw)
To: git; +Cc: Johannes.Schindelin, gitster, Ralf Thielow
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
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
^ permalink raw reply related [flat|nested] 6+ messages in thread
* Re: [PATCH v2] string_list: use string-list API in unsorted_string_list_lookup()
2016-04-25 17:40 ` [PATCH v2] " Ralf Thielow
@ 2016-04-25 17:47 ` Stefan Beller
2016-04-26 15:42 ` Johannes Schindelin
1 sibling, 0 replies; 6+ messages in thread
From: Stefan Beller @ 2016-04-25 17:47 UTC (permalink / raw)
To: Ralf Thielow; +Cc: git@vger.kernel.org, Johannes Schindelin, Junio C Hamano
On Mon, Apr 25, 2016 at 10:40 AM, Ralf Thielow <ralf.thielow@gmail.com> wrote:
> 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>
>
> 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
>
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH v2] string_list: use string-list API in unsorted_string_list_lookup()
2016-04-25 17:40 ` [PATCH v2] " Ralf Thielow
2016-04-25 17:47 ` Stefan Beller
@ 2016-04-26 15:42 ` Johannes Schindelin
1 sibling, 0 replies; 6+ messages in thread
From: Johannes Schindelin @ 2016-04-26 15:42 UTC (permalink / raw)
To: Ralf Thielow; +Cc: git, gitster
Hi Ralf,
On Mon, 25 Apr 2016, Ralf Thielow wrote:
> 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
ACK!
Dscho
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2016-04-26 15:43 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
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
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
Code repositories for project(s) associated with this public inbox
https://80x24.org/mirrors/git.git
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).