On Sep 23, 2009, at 2:27 PM, Matt Gough wrote:
I have an NSEnumerator iterating over an NSMutableArray like so:

        NSEnumerator *iter = [myMutableArray objectEnumerator];

        while (syncInfo = [iter nextObject]) {
                ... Do some stuff
        }

Upon instrumenting it, I noticed that nextObject was taking over 60% of the time, and most of that time is futzing around seemingly calling __CFArrayCopyDescription.

                               1438 -[MyObj cleanSyncList]
1319 - [__NSFastEnumerationEnumerator nextObject] 1319 __NSFastEnumerationMutationHandler
                                     1239 CFCopyDescription

You have a bug. Check your console log: it's filling up with warnings that you mutated the collection during enumeration. That's not allowed with NSEnumerator.


I presume that if I swapped this for a simple :

for (i = 0; i < [myMutableArray count]; ++i) {
        syncInfo =[myMutableArray objectAtIndex:i];
        .....etc etc
}

it would speed up enormously.

It might be faster, but it might be just as buggy if you still change the array during the loop.


--
Greg Parker     gpar...@apple.com     Runtime Wrangler


_______________________________________________

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