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
                                        1239 __CFArrayCopyDescription
                                          1183 CFCopyDescription
1180 __CFBasicHashCopyDescription 1171 CFBasicHashCopyDescription
                                                1162 CFBasicHashApply
1160 __CFBasicHashCopyDescription_block_invoke_1 1070 CFCopyDescription 851 -[NSObject (NSObject) _copyDescription] 849 -[NSDate description] 847 - [NSDate descriptionWithLocale:] 435 CFDateFormatterSetFormat 427 __ResetUDateFormat 382 udat_open 351 icu::DateFormat::create(icu::DateFormat::EStyle, icu::DateFormat::EStyle, icu::Locale const&) 349 icu::SimpleDateFormat::SimpleDateFormat(icu::DateFormat::EStyle, icu::DateFormat::EStyle, icu::Locale const&, UErrorCode&) 347 icu::SimpleDateFormat::construct(icu::DateFormat::EStyle, icu::DateFormat::EStyle, icu::Locale const&, UErrorCode&) 231 icu::SimpleDateFormat::initializeSymbols(icu::Locale const&, icu::Calendar*, UErrorCode&) 231 icu::DateFormatSymbols::DateFormatSymbols(icu::Locale const&, char const*, UErrorCode&) 230 icu::DateFormatSymbols::initializeData(icu::Locale const&, char const*, UErrorCode&, signed char) 166 icu::GregorianCalendar::GregorianCalendar(icu::GregorianCalendar const&)

Why!!

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.

I just don't understand why a supposedly fast enumerator is doing such a seemingly stupid thing as to get the description of the array each time around.

Any clues?

Matt Gough

BTW - OS X 10.6.1
_______________________________________________

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