Permalink
Browse files

Invert logic to handle most special cases first, then fall back to ge…

…neric case
  • Loading branch information...
1 parent 66fbf7a commit a086fe837d13a5e467711006d2cb4d314edabe0f Stig Brautaset committed Mar 20, 2012
Showing with 11 additions and 11 deletions.
  1. +11 −11 Classes/SBJsonTokeniser.m
View
@@ -364,20 +364,20 @@ - (sbjson_token_t)getNumberToken:(NSObject**)token {
return sbjson_token_error;
}
- if (mantissa_length > LONG_LONG_DIGITS) {
+ if (mantissa_length <= LONG_LONG_DIGITS) {
+ if (!isFloat && !hasExponent) {
+ *token = [NSNumber numberWithLongLong: isNegative ? -mantissa : mantissa];
+
+ } else {
+ *token = [NSDecimalNumber decimalNumberWithMantissa:mantissa
+ exponent:exponent
+ isNegative:isNegative];
+ }
+
+ } else {
NSString *number = [_stream stringWithRange:NSMakeRange(numberStart, _stream.index - numberStart)];
*token = [NSDecimalNumber decimalNumberWithString:number];
- } else if (!isFloat && !hasExponent) {
- if (isNegative)
- *token = [NSNumber numberWithLongLong:-mantissa];
- else
- *token = [NSNumber numberWithUnsignedLongLong:mantissa];
-
- } else {
- *token = [NSDecimalNumber decimalNumberWithMantissa:mantissa
- exponent:exponent
- isNegative:isNegative];
}
return sbjson_token_number;

0 comments on commit a086fe8

Please sign in to comment.