string_list: use string-list API in unsorted_string_list_lookup()
PATCH 1/1 string_list: use string-list API in unsorted_string_list_lookup()
Using the string-list API in function unsorted_string_list_lookup() makes the code more readable. So let's do this.
--- string-list.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-)
string-list.c +5 -4
@@ -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 ; }
Signature · 1 line
2.8.1.382.g1352ede
Hi Ralf,
Quoted 7 lines · 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 <[email protected]>--- string-list.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-)
Oh. I hoped for a reduction, not an increase.
Quoted 10 lines
string-list.c +1
-1@@ -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;
string-list.c void string_list_sort(struct string_list *list) · line 241
Quoted 10 lines
string-list.c +4
-3compare_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
Quoted 14 lines · Johannes Schindelin
string-list.c void string_list_sort(struct string_list *list) · line 241
Quoted 9 lines
string-list.c +4
-3-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!
Quoted 4 lines
In any case, I like the simplification of the code.
Ciao,
Dscho
PATCH v2 1/1 string_list: use string-list API in unsorted_string_list_lookup()
In reply to Ralf ThielowUsing the string-list API in function unsorted_string_list_lookup() makes the code more readable.
---
Changes since v1:
- remove extra curly braces
string-list.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)
string-list.c +4 -4
@@ -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 ; }
Signature · 1 line
2.8.1.430.g7c694c5
Quoted 7 lines · Ralf Thielow
Using the string-list API in function
unsorted_string_list_lookup()makes the code more readable.Signed-off-by Ralf Thielow <[email protected]>---
Changes since v1:
- remove extra curly braces
Quoted 28 lines
string-list.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)string-list.c +4
-5@@ -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
Hi Ralf,
Quoted 7 lines · Ralf Thielow
Using the string-list API in function
unsorted_string_list_lookup()makes the code more readable.Signed-off-by Ralf Thielow <[email protected]>---
Changes since v1:
- remove extra curly braces
ACK!
Dscho