dumping ground for random patches and texts
 help / color / mirror / Atom feed
From: Eric Wong <normalperson@yhbt.net>
To: ccan@lists.ozlabs.org
Cc: david@gibson.dropbear.id.au, spew@80x24.org,
	Eric Wong <normalperson@yhbt.net>
Subject: [PATCH 3/5] list: new list_for_each{,_safe}_off_dir_ macros
Date: Fri, 24 Oct 2014 22:02:30 +0000	[thread overview]
Message-ID: <1414188152-24228-4-git-send-email-normalperson@yhbt.net> (raw)
In-Reply-To: <1414188152-24228-1-git-send-email-normalperson@yhbt.net>

These internal iteration macros will make implementing reverse
iteration simpler.  For now, reimplement existing list_for_each_off
and list_for_each_safe_off macros on top of these macros to
prove they pass existing tests.

Signed-off-by: Eric Wong <normalperson@yhbt.net>
---
 ccan/list/list.h | 34 ++++++++++++++++++++--------------
 1 file changed, 20 insertions(+), 14 deletions(-)

diff --git a/ccan/list/list.h b/ccan/list/list.h
index 983675b..90989c5 100644
--- a/ccan/list/list.h
+++ b/ccan/list/list.h
@@ -653,6 +653,24 @@ static inline void list_prepend_list_(struct list_head *to,
 	list_head_init(from);
 }
 
+/* internal macros, do not use directly */
+#define list_for_each_off_dir_(h, i, off, dir)				\
+	for (i = list_node_to_off_(list_debug(h, LIST_LOC)->n.dir,	\
+				   (off));				\
+	list_node_from_off_((void *)i, (off)) != &(h)->n;		\
+	i = list_node_to_off_(list_node_from_off_((void *)i, (off))->dir, \
+			      (off)))
+
+#define list_for_each_safe_off_dir_(h, i, nxt, off, dir)		\
+	for (i = list_node_to_off_(list_debug(h, LIST_LOC)->n.dir,	\
+				   (off)),				\
+	nxt = list_node_to_off_(list_node_from_off_(i, (off))->dir,	\
+				(off));					\
+	list_node_from_off_(i, (off)) != &(h)->n;			\
+	i = nxt,							\
+	nxt = list_node_to_off_(list_node_from_off_(i, (off))->dir,	\
+				(off)))
+
 /**
  * list_for_each_off - iterate through a list of memory regions.
  * @h: the list_head
@@ -683,11 +701,7 @@ static inline void list_prepend_list_(struct list_head *to,
  *		printf("Name: %s\n", child->name);
  */
 #define list_for_each_off(h, i, off)                                    \
-	for (i = list_node_to_off_(list_debug(h, LIST_LOC)->n.next,	\
-				   (off));				\
-       list_node_from_off_((void *)i, (off)) != &(h)->n;                \
-       i = list_node_to_off_(list_node_from_off_((void *)i, (off))->next, \
-                             (off)))
+	list_for_each_off_dir_((h),(i),(off),next)
 
 /**
  * list_for_each_safe_off - iterate through a list of memory regions, maybe
@@ -706,15 +720,7 @@ static inline void list_prepend_list_(struct list_head *to,
  *		printf("Name: %s\n", child->name);
  */
 #define list_for_each_safe_off(h, i, nxt, off)                          \
-	for (i = list_node_to_off_(list_debug(h, LIST_LOC)->n.next,	\
-				   (off)),				\
-         nxt = list_node_to_off_(list_node_from_off_(i, (off))->next,   \
-                                 (off));                                \
-       list_node_from_off_(i, (off)) != &(h)->n;                        \
-       i = nxt,                                                         \
-         nxt = list_node_to_off_(list_node_from_off_(i, (off))->next,   \
-                                 (off)))
-
+	list_for_each_safe_off_dir_((h),(i),(nxt),(off),next)
 
 /* Other -off variants. */
 #define list_entry_off(n, type, off)		\
-- 
EW


  parent reply	other threads:[~2014-10-24 22:02 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-10-24 22:02 [PATCH 0/5] new ccan/list functionality Eric Wong
2014-10-24 22:02 ` [RESEND PATCH 1/5] list: list_add_after and list_add_before functions Eric Wong
2014-10-24 22:02 ` [RESEND PATCH 2/5] list: list_swap to exchange elements Eric Wong
2014-10-24 22:02 ` Eric Wong [this message]
2014-11-03  9:14   ` [PATCH 3/5] list: new list_for_each{,_safe}_off_dir_ macros David Gibson
2014-10-24 22:02 ` [PATCH 4/5] list: add list_for_each_rev_off macro Eric Wong
2014-11-03  9:16   ` David Gibson
2014-10-24 22:02 ` [PATCH 5/5] list: add list_for_each_rev_safe{,_off} macros Eric Wong
2014-11-03  9:30   ` David Gibson
2014-12-18 19:40     ` Eric Wong
2015-03-30  6:27       ` [ccan] [PATCH 5/5] list: add list_for_each_rev_safe{, _off} macros Rusty Russell

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=1414188152-24228-4-git-send-email-normalperson@yhbt.net \
    --to=normalperson@yhbt.net \
    --cc=ccan@lists.ozlabs.org \
    --cc=david@gibson.dropbear.id.au \
    --cc=spew@80x24.org \
    /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 read-only IMAP folder(s) and NNTP newsgroup(s).