• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: loop efficiency & messages
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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
References: 
 >Re: loop efficiency & messages (From: Hamish Allan <email@hidden>)

  • Prev by Date: Re: A Challenge WAS Accessor method idioms...
  • Next by Date: URL Escaping weirdness
  • Previous by thread: Re: loop efficiency & messages
  • Next by thread: Re: loop efficiency & messages
  • Index(es):
    • Date
    • Thread