Re: loop efficiency & messages
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