Skip to content

Commit 8d31635

Browse files
raalkmlgitster
authored andcommitted
Add a for_each_string_list_item macro
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 45e9a82 commit 8d31635

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

string-list.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,12 @@ void string_list_clear(struct string_list *list, int free_util);
2020
typedef void (*string_list_clear_func_t)(void *p, const char *str);
2121
void string_list_clear_func(struct string_list *list, string_list_clear_func_t clearfunc);
2222

23-
/* Use this function to iterate over each item */
23+
/* Use this function or the macro below to iterate over each item */
2424
typedef int (*string_list_each_func_t)(struct string_list_item *, void *);
2525
int for_each_string_list(struct string_list *list,
2626
string_list_each_func_t, void *cb_data);
27+
#define for_each_string_list_item(item,list) \
28+
for (item = (list)->items; item < (list)->items + (list)->nr; ++item)
2729

2830
/* Use these functions only on sorted lists: */
2931
int string_list_has_string(const struct string_list *list, const char *string);

0 commit comments

Comments
 (0)