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 4/5] list: add list_for_each_rev_off macro
Date: Fri, 24 Oct 2014 22:02:31 +0000	[thread overview]
Message-ID: <1414188152-24228-5-git-send-email-normalperson@yhbt.net> (raw)
In-Reply-To: <1414188152-24228-1-git-send-email-normalperson@yhbt.net>

And re-implement list_for_each_rev in terms of list_for_each_rev_off
to avoid duplicating iteration logic.

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

diff --git a/ccan/list/list.h b/ccan/list/list.h
index 90989c5..aaf135d 100644
--- a/ccan/list/list.h
+++ b/ccan/list/list.h
@@ -522,9 +522,7 @@ static inline const void *list_tail_(const struct list_head *h, size_t off)
  *		printf("Name: %s\n", child->name);
  */
 #define list_for_each_rev(h, i, member)					\
-	for (i = container_of_var(list_debug(h,	LIST_LOC)->n.prev, i, member); \
-	     &i->member != &(h)->n;					\
-	     i = container_of_var(i->member.prev, i, member))
+	list_for_each_rev_off(h, i, list_off_var_(i, member))
 
 /**
  * list_for_each_safe - iterate through a list, maybe during deletion
@@ -704,6 +702,17 @@ static inline void list_prepend_list_(struct list_head *to,
 	list_for_each_off_dir_((h),(i),(off),next)
 
 /**
+ * list_for_each_rev_off - iterate through a list of memory regions backwards
+ * @h: the list_head
+ * @i: the pointer to a memory region wich contains list node data.
+ * @off: offset(relative to @i) at which list node data resides.
+ *
+ * See list_for_each_off for details
+ */
+#define list_for_each_rev_off(h, i, off)                                    \
+	list_for_each_off_dir_((h),(i),(off),prev)
+
+/**
  * list_for_each_safe_off - iterate through a list of memory regions, maybe
  * during deletion
  * @h: the list_head
-- 
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 ` [PATCH 3/5] list: new list_for_each{,_safe}_off_dir_ macros Eric Wong
2014-11-03  9:14   ` David Gibson
2014-10-24 22:02 ` Eric Wong [this message]
2014-11-03  9:16   ` [PATCH 4/5] list: add list_for_each_rev_off macro 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-5-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).