block: convert ata_port_for_each_link to use a while loop to reduce code size
PATCH 1/1 block: convert ata_port_for_each_link to use a while loop to reduce code size
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
----
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
include/linux/libata.h +4 -4
@@ -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)))#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; \
Quoted 23 lines · Richard Kennedy
convert a for loop to a while loop in the
ata_port_for_each_linkmacros to reduce code size.on
x86_64size reports reduction of text size inlibata.ko : -272 bytes ahci.ko : -44 bytesSigned-off-by Richard Kennedy <[email protected]>----
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
Richardinclude/linux/libata.h +0
-0
include/linux/libata.h extern struct ata_link · line 1288
Quoted 8 lines
include/linux/libata.h +2
-2@@ -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
Quoted 8 lines
include/linux/libata.h +2
-2#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; \
Signature · 5 lines
Alexander van Heukelum [email protected] -- http://www.fastmail.fm - mmm... Fastmail...
Quoted 53 lines · Alexander van Heukelum
Quoted 23 lines · Richard Kennedy
convert a for loop to a while loop in the
ata_port_for_each_linkmacros to reduce code size.on
x86_64size reports reduction of text size inlibata.ko : -272 bytes ahci.ko : -44 bytesSigned-off-by Richard Kennedy <[email protected]>----
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
Richardinclude/linux/libata.h +0
-0include/linux/libata.h extern struct ata_link · line 1288
Quoted 8 lines
include/linux/libata.h +2
-2@@ -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
Quoted 11 lines
Quoted 8 lines
include/linux/libata.h +2
-2#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; \Signature · 2 lines
Alexander van Heukelum [email protected]
yes of course, that is the problem with this kind of macro :(
IMHO, this particular macro doesn't improve the overall code readability so would be better being removed altogether. Whenever possible I much prefer being able to see a for or while loop in the code rather than hidden in a macro somewhere, but maybe that's just me ;) regards
Richard