This introduces a tiny simplification in number parsing. (#910)
* This introduces a tiny simplification in number parsing. * Removing unnecessary function. Co-authored-by: Daniel Lemire <lemire@gmai.com>
This commit is contained in:
parent
ae6dddfff4
commit
52f44de257
|
@ -214,26 +214,6 @@ really_inline bool is_integer(char c) {
|
||||||
// this gets compiled to (uint8_t)(c - '0') <= 9 on all decent compilers
|
// this gets compiled to (uint8_t)(c - '0') <= 9 on all decent compilers
|
||||||
}
|
}
|
||||||
|
|
||||||
// We need to check that the character following a zero is valid. This is
|
|
||||||
// probably frequent and it is harder than it looks. We are building all of this
|
|
||||||
// just to differentiate between 0x1 (invalid), 0,1 (valid) 0e1 (valid)...
|
|
||||||
const bool structural_or_whitespace_or_exponent_or_decimal_negated[256] = {
|
|
||||||
1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 1, 1, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
|
|
||||||
1, 1, 1, 1, 1, 1, 1, 1, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 1, 0, 1,
|
|
||||||
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 1, 1,
|
|
||||||
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 1, 0, 1, 1,
|
|
||||||
1, 1, 1, 1, 1, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
|
|
||||||
1, 1, 1, 0, 1, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
|
|
||||||
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
|
|
||||||
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
|
|
||||||
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
|
|
||||||
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
|
|
||||||
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1};
|
|
||||||
|
|
||||||
really_inline bool
|
|
||||||
is_not_structural_or_whitespace_or_exponent_or_decimal(unsigned char c) {
|
|
||||||
return structural_or_whitespace_or_exponent_or_decimal_negated[c];
|
|
||||||
}
|
|
||||||
|
|
||||||
// check quickly whether the next 8 chars are made of digits
|
// check quickly whether the next 8 chars are made of digits
|
||||||
// at a glance, it looks better than Mula's
|
// at a glance, it looks better than Mula's
|
||||||
|
@ -393,7 +373,7 @@ really_inline bool parse_number(UNUSED const uint8_t *const src,
|
||||||
uint64_t i; // an unsigned int avoids signed overflows (which are bad)
|
uint64_t i; // an unsigned int avoids signed overflows (which are bad)
|
||||||
if (*p == '0') { // 0 cannot be followed by an integer
|
if (*p == '0') { // 0 cannot be followed by an integer
|
||||||
++p;
|
++p;
|
||||||
if (is_not_structural_or_whitespace_or_exponent_or_decimal(*p)) {
|
if (is_integer(*p)) {
|
||||||
#ifdef JSON_TEST_NUMBERS // for unit testing
|
#ifdef JSON_TEST_NUMBERS // for unit testing
|
||||||
found_invalid_number(src);
|
found_invalid_number(src);
|
||||||
#endif
|
#endif
|
||||||
|
|
Loading…
Reference in New Issue