Re: [__NSFastEnumerationEnumerator nextObject] unexpectedly not very fast!
Re: [__NSFastEnumerationEnumerator nextObject] unexpectedly not very fast!
- Subject: Re: [__NSFastEnumerationEnumerator nextObject] unexpectedly not very fast!
- From: Jens Alfke <email@hidden>
- Date: Wed, 23 Sep 2009 16:15:13 -0700
On Sep 23, 2009, at 2:27 PM, Matt Gough wrote:
NSEnumerator *iter = [myMutableArray objectEnumerator];
while (syncInfo = [iter nextObject]) {
... Do some stuff
}
That's not a fast enumerator; that's the old-fashioned slow
enumerator. (Although as already pointed out, the major slowness you
saw was caused by warnings being logged, not by the type of
enumeration.)
If you want fast enumeration you have to use the Obj-C 2.0 for...in
loop syntax:
for (syncInfo in myMutableArray) {
.. Do some stuff
}
This is the fastest and clearest way to iterate. Under the hood the
fast-enumeration API is being used to fetch multiple objects out of
the collection in bulk and pass them one by one to your code, without
having to allocate new objects or send a message every time.
—Jens_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden