Re: Home-brewed code is 100X faster than -[NSScanner scanDecimal:] ??
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