• 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: 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


  • Follow-Ups:
    • Re: [__NSFastEnumerationEnumerator nextObject] unexpectedly not very fast!
      • From: Graham Cox <email@hidden>
References: 
 >[__NSFastEnumerationEnumerator nextObject] unexpectedly not very fast! (From: Matt Gough <email@hidden>)

  • Prev by Date: Re: [__NSFastEnumerationEnumerator nextObject] unexpectedly not very fast!
  • Next by Date: Re: Mysterious Snow Crash
  • Previous by thread: Re: [__NSFastEnumerationEnumerator nextObject] unexpectedly not very fast!
  • Next by thread: Re: [__NSFastEnumerationEnumerator nextObject] unexpectedly not very fast!
  • Index(es):
    • Date
    • Thread