git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
* [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

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).