From: "Alexander van Heukelum" <heukelum@fastmail.fm>
To: "Richard Kennedy" <richard@rsk.demon.co.uk>, jgarzik@pobox.com
Cc: "lkml" <linux-kernel@vger.kernel.org>
Subject: Re: [PATCH] block: convert ata_port_for_each_link to use a while loop to reduce code size
Date: Wed, 22 Oct 2008 08:17:06 +0200 [thread overview]
Message-ID: <1224656226.15955.1280589369@webmail.messagingengine.com> (raw)
In-Reply-To: <1224620672.3110.59.camel@castor.localdomain>
On Tue, 21 Oct 2008 21:24:32 +0100, "Richard Kennedy"
<richard@rsk.demon.co.uk> said:
> convert a for loop to a while loop in the ata_port_for_each_link macros
> to reduce code size.
>
> on x86_64 size reports reduction of text size in
> libata.ko : -272 bytes
> ahci.ko : -44 bytes
>
> Signed-off-by: Richard Kennedy <richard@rsk.demon.co.uk>
>
> ----
> This patch is against 2.6.27 git head.
>
> I've been running this patch on my AMD64 desktop machine for several
> days & have not seen any problems.
> regards
> Richard
>
>
> diff --git a/include/linux/libata.h b/include/linux/libata.h
> index 947cf84..bbe3b9d 100644
> --- a/include/linux/libata.h
> +++ b/include/linux/libata.h
> @@ -1283,12 +1283,12 @@ extern struct ata_link
> *__ata_port_next_link(struct ata_port *ap,
> bool dev_only);
>
> #define __ata_port_for_each_link(link, ap) \
> - for ((link) = __ata_port_next_link((ap), NULL, false); (link); \
> - (link) = __ata_port_next_link((ap), (link), false))
> + (link) = NULL; \
> + while (((link) = __ata_port_next_link((ap), (link), false)))
Hi Richard,
Please imagine how this expands...
if (some_condition)
__ata_port_for_each_link(link, ap)
do_something(...)
But it is probably possible to get the same size reduction by
changing the for-loop like this (safety parentheses left out):
for (link = NULL;
link = __ata_port_next_link(ap, link, false), link; )
Some programmers think this is abuse of the for-construct, though ;).
Greetings,
Alexander
> #define ata_port_for_each_link(link, ap) \
> - for ((link) = __ata_port_next_link((ap), NULL, true); (link); \
> - (link) = __ata_port_next_link((ap), (link), true))
> + (link) = NULL; \
> + while (((link) = __ata_port_next_link((ap), (link), true)))
>
> #define ata_link_for_each_dev(dev, link) \
> for ((dev) = (link)->device; \
--
Alexander van Heukelum
heukelum@fastmail.fm
--
http://www.fastmail.fm - mmm... Fastmail...
next prev parent reply other threads:[~2008-10-22 6:17 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2008-10-21 20:24 [PATCH] block: convert ata_port_for_each_link to use a while loop to reduce code size Richard Kennedy
2008-10-22 6:17 ` Alexander van Heukelum [this message]
2008-10-22 8:02 ` Richard Kennedy
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=1224656226.15955.1280589369@webmail.messagingengine.com \
--to=heukelum@fastmail.fm \
--cc=jgarzik@pobox.com \
--cc=linux-kernel@vger.kernel.org \
--cc=richard@rsk.demon.co.uk \
/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