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 protected])
Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/webobjects-dev/mschrag% 40mdimension.com

This email sent to [EMAIL PROTECTED]

_______________________________________________
Do not post admin requests to the list. They will be ignored.
Webobjects-dev mailing list      ([email protected])
Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/webobjects-dev/archive%40mail-archive.com

This email sent to [email protected]

Reply via email to