From: Matthew Wilcox <matthew@wil.cx>
To: kernel-janitors@vger.kernel.org
Subject: Re: [KJ] [third][PATCH 3/4][2.6 drivers/net/skfp/smt.c:]replace SIZE
Date: Mon, 16 Jul 2007 17:25:32 +0000 [thread overview]
Message-ID: <20070716172531.GL13826@parisc-linux.org> (raw)
In-Reply-To: <20070716141818.30653.70760.sendpatchset@shcherbakov.homelinux.net>
On Mon, Jul 16, 2007 at 07:06:36PM +0200, walter harms wrote:
> your patch seems ok but the stile here ...
>
> pd=smt_pdef;
> for(i=ARRAY_SIZE(smt_pdef);i;i--) {
> if (pd->ptype = type)
> break ;
> else pd++;
> }
>
> normally i would say it should be more like for(i=0;i<ARRAY_SIZE(smt_pdef);i++) (rule of least surprise)
> but i have no clue why he did it not this way.
I can think of three possible reasons:
1. Speed. Many processors have a 'branch if not zero' instruction.
You can often eliminate one instruction per loop by counting down to
zero instead of up to N.
2. Duplicate entries. If you want to find the last item in the list
which has ptype = type, you need to start at the end, not the front.
3. Speed. If you're likely to be removing entries from a list in the
opposite order to which you added them (a stack rather than a queue),
you'll find it more quickly on average if you start at the end than at
the beginning.
There may be other reasons for iterating in the opposite direction;
those are just three possible reasons that popped into my head when you
asked the question.
--
"Bill, look, we understand that you're interested in selling us this
operating system, but compare it to ours. We can't possibly take such
a retrograde step."
_______________________________________________
REMINDER: this mailing list moved to vger.kernel.org and current one will be discontinued soon.
To resubscribe, send email to majordomo@vger.kernel.org with
"subscribe kernel-janitors" in message body and follow instructions.
Kernel-janitors mailing list
Kernel-janitors@lists.linux-foundation.org
https://lists.linux-foundation.org/mailman/listinfo/kernel-janitors
next prev parent reply other threads:[~2007-07-16 17:25 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2007-07-16 14:06 [KJ] [third][PATCH 3/4][2.6 drivers/net/skfp/smt.c:]replace SIZE acripps
2007-07-16 17:06 ` walter harms
2007-07-16 17:24 ` Nishanth Aravamudan
2007-07-16 17:25 ` Matthew Wilcox [this message]
2007-07-16 17:33 ` Cripps
2007-07-16 17:48 ` Matthew Wilcox
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=20070716172531.GL13826@parisc-linux.org \
--to=matthew@wil.cx \
--cc=kernel-janitors@vger.kernel.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.