* [PATCH] hlist_for_each_safe cleanup
@ 2004-07-23 21:05 Stephen Hemminger
2004-07-23 21:22 ` Andreas Schwab
0 siblings, 1 reply; 5+ messages in thread
From: Stephen Hemminger @ 2004-07-23 21:05 UTC (permalink / raw)
To: Andrew Morton; +Cc: linux-kernel
Make code for hlist_for_each_safe use better code (same as hlist_for_each_entry_safe).
Get rid of comment about prefetch, because that was fixed a while ago.
Only current use of this is in the bridge code, that I maintain.
Signed-off-by: Stephen Hemminger <shemminger@osdl.org>
--- linux-2.6/include/linux/list.h 2004-07-23 09:36:18.000000000 -0700
+++ tcp-2.6/include/linux/list.h 2004-07-23 11:43:25.000000000 -0700
@@ -620,13 +620,12 @@
#define hlist_entry(ptr, type, member) container_of(ptr,type,member)
-/* Cannot easily do prefetch unfortunately */
#define hlist_for_each(pos, head) \
for (pos = (head)->first; pos && ({ prefetch(pos->next); 1; }); \
pos = pos->next)
#define hlist_for_each_safe(pos, n, head) \
- for (pos = (head)->first; n = pos ? pos->next : NULL, pos; \
+ for (pos = (head)->first; pos && ({ n = pos->next; 1; }); \
pos = n)
/**
^ permalink raw reply [flat|nested] 5+ messages in thread* Re: [PATCH] hlist_for_each_safe cleanup
2004-07-23 21:05 [PATCH] hlist_for_each_safe cleanup Stephen Hemminger
@ 2004-07-23 21:22 ` Andreas Schwab
2004-07-23 22:56 ` Stephen Hemminger
0 siblings, 1 reply; 5+ messages in thread
From: Andreas Schwab @ 2004-07-23 21:22 UTC (permalink / raw)
To: Stephen Hemminger; +Cc: Andrew Morton, linux-kernel
Stephen Hemminger <shemminger@osdl.org> writes:
> --- linux-2.6/include/linux/list.h 2004-07-23 09:36:18.000000000 -0700
> +++ tcp-2.6/include/linux/list.h 2004-07-23 11:43:25.000000000 -0700
> @@ -620,13 +620,12 @@
>
> #define hlist_entry(ptr, type, member) container_of(ptr,type,member)
>
> -/* Cannot easily do prefetch unfortunately */
> #define hlist_for_each(pos, head) \
> for (pos = (head)->first; pos && ({ prefetch(pos->next); 1; }); \
> pos = pos->next)
>
> #define hlist_for_each_safe(pos, n, head) \
> - for (pos = (head)->first; n = pos ? pos->next : NULL, pos; \
> + for (pos = (head)->first; pos && ({ n = pos->next; 1; }); \
What's wrong with using the comma operator instead of non-standard
statement expressions?
Andreas.
--
Andreas Schwab, SuSE Labs, schwab@suse.de
SuSE Linux AG, Maxfeldstraße 5, 90409 Nürnberg, Germany
Key fingerprint = 58CA 54C7 6D53 942B 1756 01D3 44D5 214B 8276 4ED5
"And now for something completely different."
^ permalink raw reply [flat|nested] 5+ messages in thread* Re: [PATCH] hlist_for_each_safe cleanup
2004-07-23 21:22 ` Andreas Schwab
@ 2004-07-23 22:56 ` Stephen Hemminger
2004-07-23 23:13 ` Andreas Schwab
2004-07-25 9:32 ` Herbert Xu
0 siblings, 2 replies; 5+ messages in thread
From: Stephen Hemminger @ 2004-07-23 22:56 UTC (permalink / raw)
To: Andreas Schwab; +Cc: Andrew Morton, linux-kernel
On Fri, 23 Jul 2004 23:22:23 +0200
Andreas Schwab <schwab@suse.de> wrote:
> Stephen Hemminger <shemminger@osdl.org> writes:
>
> > --- linux-2.6/include/linux/list.h 2004-07-23 09:36:18.000000000 -0700
> > +++ tcp-2.6/include/linux/list.h 2004-07-23 11:43:25.000000000 -0700
> > @@ -620,13 +620,12 @@
> >
> > #define hlist_entry(ptr, type, member) container_of(ptr,type,member)
> >
> > -/* Cannot easily do prefetch unfortunately */
> > #define hlist_for_each(pos, head) \
> > for (pos = (head)->first; pos && ({ prefetch(pos->next); 1; }); \
> > pos = pos->next)
> >
> > #define hlist_for_each_safe(pos, n, head) \
> > - for (pos = (head)->first; n = pos ? pos->next : NULL, pos; \
> > + for (pos = (head)->first; pos && ({ n = pos->next; 1; }); \
>
> What's wrong with using the comma operator instead of non-standard
> statement expressions?
It was more a case of consistency and avoiding the n = NULL assignment when pos
is NULL.
Look at hlist_for_each_entry_safe
#define hlist_for_each_entry_safe(tpos, pos, n, head, member) \
for (pos = (head)->first; \
pos && ({ n = pos->next; 1; }) && \
({ tpos = hlist_entry(pos, typeof(*tpos), member); 1;}); \
pos = n)
What's your problem with the gcc extensions, the kernel uses them all over the place,
planning on starting a conversion?
^ permalink raw reply [flat|nested] 5+ messages in thread* Re: [PATCH] hlist_for_each_safe cleanup
2004-07-23 22:56 ` Stephen Hemminger
@ 2004-07-23 23:13 ` Andreas Schwab
2004-07-25 9:32 ` Herbert Xu
1 sibling, 0 replies; 5+ messages in thread
From: Andreas Schwab @ 2004-07-23 23:13 UTC (permalink / raw)
To: Stephen Hemminger; +Cc: Andrew Morton, linux-kernel
Stephen Hemminger <shemminger@osdl.org> writes:
> What's your problem with the gcc extensions, the kernel uses them all over the place,
> planning on starting a conversion?
Why use an extension when an equivalent standard construct exists that is
no less readable?
Andreas.
--
Andreas Schwab, SuSE Labs, schwab@suse.de
SuSE Linux AG, Maxfeldstraße 5, 90409 Nürnberg, Germany
Key fingerprint = 58CA 54C7 6D53 942B 1756 01D3 44D5 214B 8276 4ED5
"And now for something completely different."
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH] hlist_for_each_safe cleanup
2004-07-23 22:56 ` Stephen Hemminger
2004-07-23 23:13 ` Andreas Schwab
@ 2004-07-25 9:32 ` Herbert Xu
1 sibling, 0 replies; 5+ messages in thread
From: Herbert Xu @ 2004-07-25 9:32 UTC (permalink / raw)
To: Stephen Hemminger; +Cc: schwab, akpm, linux-kernel
Stephen Hemminger <shemminger@osdl.org> wrote:
> On Fri, 23 Jul 2004 23:22:23 +0200
>
>> What's wrong with using the comma operator instead of non-standard
>> statement expressions?
>
> It was more a case of consistency and avoiding the n = NULL assignment when pos
> is NULL.
>
> Look at hlist_for_each_entry_safe
>
> #define hlist_for_each_entry_safe(tpos, pos, n, head, member) \
> for (pos = (head)->first; \
> pos && ({ n = pos->next; 1; }) && \
> ({ tpos = hlist_entry(pos, typeof(*tpos), member); 1;}); \
> pos = n)
>
> What's your problem with the gcc extensions, the kernel uses them all over the place,
> planning on starting a conversion?
Yes but a comma operator will achieve exactly the same thing and is
more concise:
pos && (n = pos->next, 1) &&
You could also write
pos && ((n = pos->next) || 1) &&
Cheers,
--
Visit Openswan at http://www.openswan.org/
Email: Herbert Xu ~{PmV>HI~} <herbert@gondor.apana.org.au>
Home Page: http://gondor.apana.org.au/~herbert/
PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2004-07-25 9:37 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2004-07-23 21:05 [PATCH] hlist_for_each_safe cleanup Stephen Hemminger
2004-07-23 21:22 ` Andreas Schwab
2004-07-23 22:56 ` Stephen Hemminger
2004-07-23 23:13 ` Andreas Schwab
2004-07-25 9:32 ` Herbert Xu
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®