• 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: Guy English <email@hidden>
  • Date: Tue, 22 Mar 2005 15:39:53 -0500

Mark Dawson <email@hidden> wrote:
> int count = [self getCount];
> for (i = 0; i < count; i++)

I use this idiom all the time. I believe you'll get a message dispatch
each iteration with the alternative. How much that matters really
depends on profiling and your data set. Because of the dynamic nature
of the Objective-C runtime it's really hard, if not impossible, for
the compiler to be able to optimize that count call away. Inside your
loop you could call code that will load a category on your object that
overrides getCount for example. Or, and this is a trickier one, an
key-value observer may get called without your explicit knowledge and
load the category. Lots of things can happen in Objective-C that make
inlining getters like that really hard to do.

Guy
 _______________________________________________
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: 
 >loop efficiency & messages (From: Mark Dawson <email@hidden>)

  • Prev by Date: Re: [OT] Application ideas
  • Next by Date: Re: path question
  • Previous by thread: loop efficiency & messages
  • Next by thread: Re: loop efficiency & messages
  • Index(es):
    • Date
    • Thread