* [PATCH] list_for_each_entry
@ 2002-08-28 1:52 Rusty Russell
0 siblings, 0 replies; 2+ messages in thread
From: Rusty Russell @ 2002-08-28 1:52 UTC (permalink / raw)
To: torvalds, marcelo; +Cc: linux-kernel
List iteration pain removal patch.
Marcelo, Linus, please apply.
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 .5652-linux-2.5.31/include/linux/list.h .5652-linux-2.5.31.updated/include/linux/list.h
--- .5652-linux-2.5.31/include/linux/list.h 2002-08-02 11:15:10.000000000 +1000
+++ .5652-linux-2.5.31.updated/include/linux/list.h 2002-08-22 10:38:52.000000000 +1000
@@ -211,6 +211,19 @@ static inline void list_splice_init(list
for (pos = (head)->next, n = pos->next; pos != (head); \
pos = n, n = pos->next)
+/**
+ * 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 */
#endif
^ permalink raw reply [flat|nested] 2+ messages in thread
* [PATCH] list_for_each_entry
@ 2002-08-21 9:39 Rusty Russell
0 siblings, 0 replies; 2+ messages in thread
From: Rusty Russell @ 2002-08-21 9:39 UTC (permalink / raw)
To: linux-kernel; +Cc: torvalds
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 */
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2002-08-28 1:58 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2002-08-28 1:52 [PATCH] list_for_each_entry Rusty Russell
-- strict thread matches above, loose matches on Subject: below --
2002-08-21 9:39 Rusty Russell
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).