git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH 1/2] Add a for_each_string_list_item macro

From
Alex Riesen <raa.lkml@gmail.com>
Date
Jul 3, 2010, 12:40 UTC
Message-ID
<20100703124004.GA5511@blimp.localdomain>
In-Reply-To
<20100702205417.GA4941@blimp.localdomain>

This is more lightweight than a call to for_each_string_list function with callback function and a cookie argument.

Signed-off-by: Alex Riesen <raa.lkml@gmail.com>
---
Alex Riesen, Fri, Jul 02, 2010 22:54:17 +0200:
Show 20 quoted lines
> This is more lightweight than for_each_string_list function with
> callback function and a cookie argument.
> 
> Signed-off-by: Alex Riesen <raa.lkml@gmail.com>
> ---
> 
> Alex Riesen, Tue, Jun 29, 2010 10:35:15 +0200:
> > On Tue, Jun 29, 2010 at 10:33, Alex Riesen <raa.lkml@gmail.com> wrote:
> > > BTW, now that I took a look at it... The iteration over string_list
> > > items looks a little overengineered. At least from the point of
> > > view of the existing users of the feature. Wouldn't a simple loop
> > > be just as simple to use (if not simplier) and faster (no uninlineable
> > > function calls and argument preparation and passing needed)?
> > >
> > > #define string_list_foreach(item,list) \
> > >        for (item = (list)->items; item < (list)->items + (list)->nr; ++item)
> > >
> 
> Rebased on current head (after Julian Philips patches).
> 
Changed the macro name to make it look like the for_each* functions.
 string-list.h |    4 +++-
 1 files changed, 3 insertions(+), 1 deletions(-)
diff --git a/string-list.h b/string-list.h
index 680d600..a37cae5 100644
--- a/string-list.h
+++ b/string-list.h
@@ -20,10 +20,12 @@ void string_list_clear(struct string_list *list, int free_util);
 typedef void (*string_list_clear_func_t)(void *p, const char *str);
 void string_list_clear_func(struct string_list *list, string_list_clear_func_t clearfunc);
 
-/* Use this function to iterate over each item */
+/* Use this function or the macro below to iterate over each item */
 typedef int (*string_list_each_func_t)(struct string_list_item *, void *);
 int for_each_string_list(struct string_list *list,
 			 string_list_each_func_t, void *cb_data);
+#define for_each_string_list_item(item,list) \
+	for (item = (list)->items; item < (list)->items + (list)->nr; ++item)
 
 /* Use these functions only on sorted lists: */
 int string_list_has_string(const struct string_list *list, const char *string);
-- 
1.7.1.304.g8446
Previous: Alex RiesenNext: Alex Riesen
Message 3 of 5 in “Add a string_list_foreach macro”
  1. 1/2 Add a string_list_foreach macroAlex Riesen, Jun 29, 2010
  2. 1/2 Add a string_list_foreach macroAlex Riesen, Jul 2, 2010
  3. 1/2 Add a for_each_string_list_item macroAlex Riesen, Jul 3, 2010
  4. 2/2 Convert the users of for_each_string_list to for_each_string_list_item macroAlex Riesen, Jul 3, 2010
  5. Junio C HamanoJul 6, 2010

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.