Mailing Lists: Apple Mailing Lists

Image of Mac OS face in stamp
 
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Speeding up XCode?



long long result = 0, intermediate, base = 10 /* Adapt to suit */;
unsigned int initialPosition, newPosition;
NSCharacterSet *decimalDigits = [NSCharacterSet decimalDigitCharacterSet];
NSScanner *scanner = [NSScanner scannerWithString:myString];


//[scanner setCharactersToBeSkipped:[decimalDigits invertedSet]];

while (![scanner isAtEnd]) {
    initialPosition = [scanner scanLocation];

    if ([scanner scanLongLong:&intermediate]) {
        newPosition = [scanner scanLocation];

        while (initialPosition < newPosition) {
            result *= base;
            ++initialPosition;
        }

        result += intermediate;
    }

    [scanner scanUpToCharactersFromSet:decimalDigits intoString:nil];
}

Dunno if it's fast, but it's accurate.

Apparently I lied. The call to NSScanner's setCharactersToBeSkipped apparently needs to be removed for this to work. Thanks to Roger (email@hidden) for pointing this out.


I don't understand why it makes a difference, though. Only if scanLongLong skips characters during conversion (not just before) would this conclusion make sense, which is exactly what the documentation says it doesn't do.

Wade Tregaskis

    ICQ: 40056898
    AIM, Yahoo & Skype: wadetregaskis
    MSN: email@hidden
    iChat & email: email@hidden
    Jabber: email@hidden
    Google Talk: email@hidden

    http://homepage.mac.com/wadetregaskis/

-- Sed quis custodiet ipsos custodes?


_______________________________________________ Do not post admin requests to the list. They will be ignored. Xcode-users mailing list (email@hidden) Help/Unsubscribe/Update your Subscription: http://lists.apple.com/mailman/options/xcode-users/email@hidden

This email sent to email@hidden
References: 
 >RE: Speeding up XCode? (From: Jeff Laing <email@hidden>)
 >Re: Speeding up XCode? (From: Robert Dell <email@hidden>)
 >Re: Speeding up XCode? (From: email@hidden)



Visit the Apple Store online or at retail locations.
1-800-MY-APPLE

Contact Apple | Terms of Use | Privacy Policy

Copyright © 2007 Apple Inc. All rights reserved.