On Sep 23, 2009, at 6:10 PM, Graham Cox wrote:

I thought that NSEnumerator was implemented in terms of fast enumeration "underneath" - the docs seem to imply that, as does the existence of __NSFastEnumerationEnumerator private class. It may be still slower than directly using the fast enumeration syntax, but isn't there some gain to be had?

Maybe some, but not much. I did a lot of profiling and experimenting with enumeration, some of which I think ended up in the NSFastEnumeration design, and I found that the message-send-per-object was the biggest part of the overhead, and the creation (and eventual cleanup) of the autoreleased NSEnumerator object was significant too. There's no way around these when using NSEnumerator directly, or even iterating arrays by index.

That said, the overhead is often not major compared with the cost of what's going on inside the body of your loop, and how often the loop runs. So I wouldn't worry unless you have done profiling that shows some of these loops as hot-spots.

—Jens_______________________________________________

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

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:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Reply via email to