From: Alex Riesen Date: Tue, 29 Jun 2010 08:35:15 GMT Subject: [PATCH 1/2] Add a string_list_foreach macro Message-ID: This is more lightweight than for_each_string_list function with callback function and a cookie argument. Signed-off-by: Alex Riesen --- On Tue, Jun 29, 2010 at 10:33, Alex Riesen 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) > string-list.h | 2 ++ 1 files changed, 2 insertions(+), 0 deletions(-) diff --git a/string-list.h b/string-list.h index 63b69c8..188d087 100644 --- a/string-list.h +++ b/string-list.h @@ -24,6 +24,8 @@ void string_list_clear_func(struct string_list *list, string_list_clear_func_t c typedef int (*string_list_each_func_t)(struct string_list_item *, void *); int for_each_string_list(string_list_each_func_t, struct string_list *list, void *cb_data); +#define string_list_foreach(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.622.g408a98 From b2e7d2dce0cb8a6b50af5ba04ededfb342643a90 Mon Sep 17 00:00:00 2001 From: Alex Riesen Date: Tue, 29 Jun 2010 10:02:44 +0200 Subject: [PATCH 1/2] Add a string_list_foreach macro This is more lightweight than for_each_string_list function with callback function and a cookie argument. Signed-off-by: Alex Riesen --- string-list.h | 2 ++ 1 files changed, 2 insertions(+), 0 deletions(-) diff --git a/string-list.h b/string-list.h index 63b69c8..188d087 100644 --- a/string-list.h +++ b/string-list.h @@ -24,6 +24,8 @@ void string_list_clear_func(struct string_list *list, string_list_clear_func_t c typedef int (*string_list_each_func_t)(struct string_list_item *, void *); int for_each_string_list(string_list_each_func_t, struct string_list *list, void *cb_data); +#define string_list_foreach(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.622.g408a98