git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Alex Riesen <raa.lkml@gmail.com>
To: Junio C Hamano <gitster@pobox.com>
Cc: Thiago Farina <tfransosi@gmail.com>,
	git@vger.kernel.org, jrnieder@gmail.com, srabbelier@gmail.com
Subject: [PATCH 1/2] Add a string_list_foreach macro
Date: Tue, 29 Jun 2010 10:35:15 +0200	[thread overview]
Message-ID: <AANLkTilj7MiqiCmptDw0PLM5QqKZOOSZnSsxMlELS_5_@mail.gmail.com> (raw)

[-- Attachment #1: Type: text/plain, Size: 1467 bytes --]

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

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

 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

[-- Attachment #2: 0001-Add-a-string_list_foreach-macro.diff --]
[-- Type: application/octet-stream, Size: 1092 bytes --]

From b2e7d2dce0cb8a6b50af5ba04ededfb342643a90 Mon Sep 17 00:00:00 2001
From: Alex Riesen <raa.lkml@gmail.com>
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 <raa.lkml@gmail.com>
---
 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


             reply	other threads:[~2010-06-29  8:35 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-06-29  8:35 Alex Riesen [this message]
2010-07-02 20:54 ` [PATCH 1/2] Add a string_list_foreach macro Alex Riesen
2010-07-03 12:40   ` [PATCH 1/2] Add a for_each_string_list_item macro Alex Riesen
2010-07-03 12:41     ` [PATCH 2/2] Convert the users of for_each_string_list to " Alex Riesen
2010-07-06  2:35       ` Junio C Hamano

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=AANLkTilj7MiqiCmptDw0PLM5QqKZOOSZnSsxMlELS_5_@mail.gmail.com \
    --to=raa.lkml@gmail.com \
    --cc=git@vger.kernel.org \
    --cc=gitster@pobox.com \
    --cc=jrnieder@gmail.com \
    --cc=srabbelier@gmail.com \
    --cc=tfransosi@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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 NNTP newsgroup(s).