@@ -416,19 +416,14 @@ really_inline bool parse_number(UNUSED const uint8_t *const src,
416
416
//
417
417
// Parse the integer part.
418
418
//
419
+ // PERF NOTE: we don't use is_made_of_eight_digits_fast because large integers like 123456789 are rare
419
420
const char *const start_digits = p;
420
- uint64_t i;
421
- if (!parse_first_digit (*p, i)) { return INVALID_NUMBER (src); }
422
- ++p;
421
+ uint64_t i = 0 ;
422
+ while (parse_digit (*p, i)) { p++; }
423
423
424
- // If the integer starts with 0, just check that there are no more digits.
425
- if (i == 0 ) {
426
- if (static_cast <unsigned char >(*p - ' 0' ) <= 9 ) { return INVALID_NUMBER (src); } // 0 cannot be followed by an integer
427
- } else {
428
- // Integer starts with 1-9. Parse the rest of the integer
429
- // PERF NOTE: we don't use is_made_of_eight_digits_fast because large integers like 123456789 are rare
430
- while (parse_digit (*p, i)) { p++; }
431
- }
424
+ // If there were no digits, or if the integer starts with 0 and has more than one digit, it's an error.
425
+ int digit_count = int (p - start_digits);
426
+ if (digit_count == 0 || (' 0' == *start_digits && digit_count > 1 )) { return INVALID_NUMBER (src); }
432
427
433
428
//
434
429
// Handle floats if there is a . or e (or both)
@@ -439,8 +434,8 @@ really_inline bool parse_number(UNUSED const uint8_t *const src,
439
434
is_float = true ;
440
435
++p;
441
436
if (!parse_decimal (src, p, i, exponent)) { return false ; }
437
+ digit_count = int (p - start_digits); // used later to guard against overflows
442
438
}
443
- int digit_count = int (p - start_digits); // used later to guard against overflows
444
439
if ((' e' == *p) || (' E' == *p)) {
445
440
is_float = true ;
446
441
++p;
0 commit comments