Mailing Lists: Apple Mailing Lists
Image of Mac OS face in stamp
Re: Fast Enumeration versus enumerateObjectsUsingBlock
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Fast Enumeration versus enumerateObjectsUsingBlock



One has now been filed, so you don't have to.  In the abstract class, there's nothing to be done but call through the defined primitive methods.  The only way to avoid the call to objectForKey: is for the concrete classes to each individually override and replace the abstract implementation with a custom implementation that replicates all the functionality with direct access to the storage of the collection objects.  for(in) already has such an override for the concrete collection classes of Foundtion.


To add my emphasis on the for(in) vs enumerate.* question, to what already has been said:  for(in) is going to be fastest, except specifically in the case of dictionaries where you need the value for the key sufficiently often or every iteration, and the concrete class you have an instance of doesn't override and replace the countBy.... NSFastEnumeration method with its own custom version.  (I'm saying 'replace' here, by which I mean you can't call super and leverage inheritance.). Although newer, the enumerate.* methods are unlikely to be faster in most non-concurrent cases.  What they bring to the table are more options, and method names that would never collide with any method anyone would actually ever put [in a category] on the collection classes.


Chris Kane
Cocoa Frameworks



On Sep 6, 2012, at 4:54, Mike Abdullah <email@hidden> wrote:

>
> On 5 Sep 2012, at 20:43, Greg Parker <email@hidden> wrote:
>
>> On Sep 5, 2012, at 10:36 AM, Bill Garrison <email@hidden> wrote:
>>> Mike Abdullah wrote a blog post on this recently, in the context of enumerating dictionaries:
>>>
>>> <http://www.mikeabdullah.net/slow-block-based-dictionary-enumeration.html>
>>>
>>> tl;dr: fast enumeration of dictionary keys FTW
>>
>> Did anyone file a bug report? Ordinary NSDictionaries shouldn't be calling -objectForKey: in -enumerateKeysAndObjectsUsingBlock: .
>
> I didn't file a bug report, because the end behaviour seemed fairly reasonable to me. Can if you'd like.
>
>
> _______________________________________________
> Do not post admin requests to the list. They will be ignored.
> Objc-language mailing list      (email@hidden)
> Help/Unsubscribe/Update your Subscription:
>
> This email sent to email@hidden

 _______________________________________________
Do not post admin requests to the list. They will be ignored.
Objc-language mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:

This email sent to email@hidden

References: 
 >Fast Enumeration versus enumerateObjectsUsingBlock (From: David Hoerl <email@hidden>)
 >Re: Fast Enumeration versus enumerateObjectsUsingBlock (From: OC <email@hidden>)
 >Re: Fast Enumeration versus enumerateObjectsUsingBlock (From: Bill Garrison <email@hidden>)
 >Re: Fast Enumeration versus enumerateObjectsUsingBlock (From: Greg Parker <email@hidden>)
 >Re: Fast Enumeration versus enumerateObjectsUsingBlock (From: Mike Abdullah <email@hidden>)



Visit the Apple Store online or at retail locations.
1-800-MY-APPLE

Contact Apple | Terms of Use | Privacy Policy

Copyright © 2011 Apple Inc. All rights reserved.