Re: loop efficiency & messages
Re: loop efficiency & messages
- Subject: Re: loop efficiency & messages
- From: Marcel Weiher <email@hidden>
- Date: Sat, 26 Mar 2005 21:52:29 +0000
On 22 Mar 2005, at 22:04, Hamish Allan wrote:
hehe. Yes, that is what I wanted to ask. The compiler certainly
couldn't infer from that code whether or not the destination of the
message will remain constant throughout the loop. However, I could
imagine this would be a desirable feature. I think MuleKybernetic (?)
had an article on "selector caching", or such, that discussed how to
solve this particular problem. I dunno if I'd consider their
technique
a compile-time feature however.
It seems to me that there's a really easy way to signal to the
compiler to cache the result of the getCount in a register:
int count = [self getCount];
for (i = 0; i < count; ++i)
Or, with nC99 syntax:
for ( int i=0, max=count; i<max; i++ ) {
// do stuff
}
Another alternative would be to use HOM for iteration, which will get
you fairly well-optimized loops (with IMP-caching and other goodies)
using a very comfortable syntax:
[[myObjects do] someSelector];
arrayResult = [[myObjects collect]
someMessageThatComputesAResult:argument];
Cheers,
Marcel
--
Marcel Weiher Metaobject Software Technologies
email@hidden www.metaobject.com
The simplicity of power HOM, IDEAs, MetaAd etc.
1d480c25f397c4786386135f8e8938e4
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden