mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Rusty Russell <rusty@rustcorp.com.au>
To: linux-kernel@vger.kernel.org
Cc: torvalds@transmeta.com
Subject: [PATCH] list_for_each_entry
Date: Wed, 21 Aug 2002 19:39:02 +1000	[thread overview]
Message-ID: <20020821053509.4D5F32C0B3@lists.samba.org> (raw)

Using two variables all the time is pissing me off:

	struct list_head *i;
	list_for_each(i, &head) {
		struct foo *f = list_entry(i, struct foo, list);
		...
	}

Much nicer is:
	struct foo *f;
	list_for_each_entry(f, &head, list) {
		...
	}

Asm code produced is identical.

Cheers,
Rusty.
--
  Anyone who quotes me in their sig is an idiot. -- Rusty Russell.

Name: list_for_each_entry patch
Author: Rusty Russell
Status: Trivial

D: This adds list_for_each_entry, which is the equivalent of
D: list_for_each and list_entry, except only one variable is needed.

diff -urpN --exclude TAGS -X /home/rusty/devel/kernel/kernel-patches/current-dontdiff --minimal linux-2.4.19/include/linux/list.h working-2.4.19-conntrack-fast/include/linux/list.h
--- linux-2.4.19/include/linux/list.h	2002-08-21 18:14:34.000000000 +1000
+++ working-2.4.19-conntrack-fast/include/linux/list.h	2002-08-21 19:35:09.000000000 +1000
@@ -171,6 +171,18 @@ static __inline__ void list_splice(struc
 	for (pos = (head)->prev, prefetch(pos->prev); pos != (head); \
         	pos = pos->prev, prefetch(pos->prev))
         	
+/**
+ * list_for_each_entry	-	iterate over list of given type
+ * @pos:	the type * to use as a loop counter.
+ * @head:	the head for your list.
+ * @member:	the name of the list_struct within the struct.
+ */
+#define list_for_each_entry(pos, head, member)				\
+	for (pos = list_entry((head)->next, typeof(*pos), member),	\
+		     prefetch(pos->member.next);			\
+	     &pos->member != (head); 					\
+	     pos = list_entry(pos->member.next, typeof(*pos), member),	\
+		     prefetch(pos->member.next))
 
 #endif /* __KERNEL__ || _LVM_H_INCLUDE */
 

             reply	other threads:[~2002-08-21 10:30 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2002-08-21  9:39 Rusty Russell [this message]
2002-08-28  1:52 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=20020821053509.4D5F32C0B3@lists.samba.org \
    --to=rusty@rustcorp.com.au \
    --cc=linux-kernel@vger.kernel.org \
    --cc=torvalds@transmeta.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

all inboxes | Powered by JetHome®