• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: [__NSFastEnumerationEnumerator nextObject] unexpectedly not very fast!
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [__NSFastEnumerationEnumerator nextObject] unexpectedly not very fast!


  • Subject: Re: [__NSFastEnumerationEnumerator nextObject] unexpectedly not very fast!
  • From: Greg Parker <email@hidden>
  • Date: Wed, 23 Sep 2009 15:56:30 -0700

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 email@hidden Runtime Wrangler


_______________________________________________

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


References: 
 >[__NSFastEnumerationEnumerator nextObject] unexpectedly not very fast! (From: Matt Gough <email@hidden>)

  • Prev by Date: Re: app delegate +initialize
  • Next by Date: Re: [__NSFastEnumerationEnumerator nextObject] unexpectedly not very fast!
  • Previous by thread: [__NSFastEnumerationEnumerator nextObject] unexpectedly not very fast!
  • Next by thread: Re: [__NSFastEnumerationEnumerator nextObject] unexpectedly not very fast!
  • Index(es):
    • Date
    • Thread