• 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: Home-brewed code is 100X faster than -[NSScanner scanDecimal:] ??
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Home-brewed code is 100X faster than -[NSScanner scanDecimal:] ??


  • Subject: Re: Home-brewed code is 100X faster than -[NSScanner scanDecimal:] ??
  • From: Jerry Krinock <email@hidden>
  • Date: Fri, 4 Feb 2011 11:39:11 -0800

Sorry, in the last message I posted some stupid code which was written too late last night.  The -scanJSONNumber:accurately: implementation should be simply this:

- (BOOL)scanJSONNumber:(NSNumber**)number
            accurately:(BOOL)accurately {
    BOOL result = NO ;

    if (!accurately) {
        double daDouble ;
        result = [self scanDouble:&daDouble] ;
        if (result) {
            *number = [NSNumber numberWithDouble:daDouble] ;
        }
    }
    else {
        NSDecimal decimal ;
        // This local autorelease pool is quite necessary, when parsing
        // strings with dense numbers, of 500K characters.  Otherwise,
        // memory allocations go into the gigabytes.
        NSAutoreleasePool* pool = [[NSAutoreleasePool alloc] init] ;
        result = [self scanDecimal:&decimal] ;
        [pool release] ;
        if (result) {
            *number = [NSDecimalNumber decimalNumberWithDecimal:decimal] ;
        }
    }

    return result ;
}

_______________________________________________

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

References: 
 >Home-brewed code is 100X faster than -[NSScanner scanDecimal:] ?? (From: Jerry Krinock <email@hidden>)
 >Re: Home-brewed code is 100X faster than -[NSScanner scanDecimal:] ?? (From: glenn andreas <email@hidden>)
 >Re: Home-brewed code is 100X faster than -[NSScanner scanDecimal:] ?? (From: Jerry Krinock <email@hidden>)
 >Re: Home-brewed code is 100X faster than -[NSScanner scanDecimal:] ?? (From: glenn andreas <email@hidden>)
 >Re: Home-brewed code is 100X faster than -[NSScanner scanDecimal:] ?? (From: Jerry Krinock <email@hidden>)

  • Prev by Date: Is childrenKeyPathForNode robust?
  • Next by Date: Identify key colour in video/photo
  • Previous by thread: Re: Home-brewed code is 100X faster than -[NSScanner scanDecimal:] ??
  • Next by thread: Localizable.strings not being read...
  • Index(es):
    • Date
    • Thread