• 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: objectEnumerator vs objectAtIndex
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: objectEnumerator vs objectAtIndex


  • Subject: Re: objectEnumerator vs objectAtIndex
  • From: Mike Schrag <email@hidden>
  • Date: Thu, 16 Feb 2006 17:17:28 -0500

For the record, they are nearly identical implementations -- the Enumeration implementation you get back (_NSJavaArrayEnumerator) has a direct reference to the object array from inside the NSArray and walks it with its own internal index, so one really isn't any better than the other. A quick timing test reveals this as well (1 million objects traversed in about 40-50ms for either one).

<minirant>it is really lame that NSArray is a concrete class and not an interface .. extending it and actually making your subclass work properly for all the methods is really hard</minirant>

ms

On Feb 16, 2006, at 5:09 PM, Chuck Hill wrote:


On Feb 16, 2006, at 1:45 PM, Marcos Trejo Munguia wrote:

Hi list:

Today a question came to my mind, which method for accessing NSArray elements is more efficient, objectEnumerator or objectAtIndex?

Thank you in advance.

objectAtIndex.

"The following table describes the NSArray methods that provide the basis for all NSArray's other methods; that is, all other methods are implemented in terms of these three. If you create a subclass of NSArray, you need only ensure that these base methods work properly. Having done so, you can be sure that all your subclass's inherited methods operate properly.

count ... objectAtIndex ... objectsNoCopy"

Assuming that the implementation matches the documentation (which might be a poor assumption), objectEnumerator should be implemented by using objectAtIndex. I would not expect the difference to be significant in either case. That would be close to the last place I would look when optimizing code.

Chuck

--
Coming in 2006 - an introduction to web applications using WebObjects and Xcode http://www.global-village.net/wointro


Practical WebObjects - for developers who want to increase their overall knowledge of WebObjects or who are trying to solve specific problems. http://www.global-village.net/products/ practical_webobjects




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


This email sent to email@hidden

_______________________________________________ Do not post admin requests to the list. They will be ignored. Webobjects-dev mailing list (email@hidden) Help/Unsubscribe/Update your Subscription: This email sent to email@hidden
  • Follow-Ups:
    • Re: objectEnumerator vs objectAtIndex [SOLVED]
      • From: Marcos Trejo Munguia <email@hidden>
References: 
 >objectEnumerator vs objectAtIndex (From: Marcos Trejo Munguia <email@hidden>)
 >Re: objectEnumerator vs objectAtIndex (From: Chuck Hill <email@hidden>)

  • Prev by Date: Re: objectEnumerator vs objectAtIndex
  • Next by Date: Re: objectEnumerator vs objectAtIndex [SOLVED]
  • Previous by thread: Re: objectEnumerator vs objectAtIndex
  • Next by thread: Re: objectEnumerator vs objectAtIndex [SOLVED]
  • Index(es):
    • Date
    • Thread