Eliminate "found_minus" parse_number() parameter
This commit is contained in:
parent
fc0102b079
commit
c64367536d
|
@ -400,19 +400,18 @@ really_inline bool write_float(const uint8_t *const src, bool negative, uint64_t
|
||||||
// Our objective is accurate parsing (ULP of 0) at high speed.
|
// Our objective is accurate parsing (ULP of 0) at high speed.
|
||||||
template<typename W>
|
template<typename W>
|
||||||
really_inline bool parse_number(UNUSED const uint8_t *const src,
|
really_inline bool parse_number(UNUSED const uint8_t *const src,
|
||||||
UNUSED bool found_minus,
|
|
||||||
W &writer) {
|
W &writer) {
|
||||||
#ifdef SIMDJSON_SKIPNUMBERPARSING // for performance analysis, it is sometimes
|
#ifdef SIMDJSON_SKIPNUMBERPARSING // for performance analysis, it is sometimes
|
||||||
// useful to skip parsing
|
// useful to skip parsing
|
||||||
writer.append_s64(0); // always write zero
|
writer.append_s64(0); // always write zero
|
||||||
return true; // always succeeds
|
return true; // always succeeds
|
||||||
#else
|
#else
|
||||||
const char *p = reinterpret_cast<const char *>(src);
|
|
||||||
bool negative = false;
|
//
|
||||||
if (found_minus) {
|
// Check for minus sign
|
||||||
++p;
|
//
|
||||||
negative = true;
|
bool negative = (*src == '-');
|
||||||
}
|
const char *p = reinterpret_cast<const char *>(src) + negative;
|
||||||
|
|
||||||
//
|
//
|
||||||
// Parse the integer part.
|
// Parse the integer part.
|
||||||
|
@ -422,8 +421,8 @@ really_inline bool parse_number(UNUSED const uint8_t *const src,
|
||||||
if (!parse_first_digit(*p, i)) { return INVALID_NUMBER(src); }
|
if (!parse_first_digit(*p, i)) { return INVALID_NUMBER(src); }
|
||||||
++p;
|
++p;
|
||||||
|
|
||||||
if (i == 0) {
|
|
||||||
// If the integer starts with 0, just check that there are no more digits.
|
// If the integer starts with 0, just check that there are no more digits.
|
||||||
|
if (i == 0) {
|
||||||
if (static_cast<unsigned char>(*p - '0') <= 9) { return INVALID_NUMBER(src); } // 0 cannot be followed by an integer
|
if (static_cast<unsigned char>(*p - '0') <= 9) { return INVALID_NUMBER(src); } // 0 cannot be followed by an integer
|
||||||
} else {
|
} else {
|
||||||
// Integer starts with 1-9. Parse the rest of the integer
|
// Integer starts with 1-9. Parse the rest of the integer
|
||||||
|
|
|
@ -159,17 +159,17 @@ struct structural_parser : structural_iterator {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
WARN_UNUSED really_inline bool parse_number(const uint8_t *src, bool found_minus) {
|
WARN_UNUSED really_inline bool parse_number(const uint8_t *src) {
|
||||||
log_value("number");
|
log_value("number");
|
||||||
bool succeeded = numberparsing::parse_number(src, found_minus, tape);
|
bool succeeded = numberparsing::parse_number(src, tape);
|
||||||
if (!succeeded) { log_error("Invalid number"); }
|
if (!succeeded) { log_error("Invalid number"); }
|
||||||
return !succeeded;
|
return !succeeded;
|
||||||
}
|
}
|
||||||
WARN_UNUSED really_inline bool parse_number(bool found_minus) {
|
WARN_UNUSED really_inline bool parse_number() {
|
||||||
return parse_number(current(), found_minus);
|
return parse_number(current());
|
||||||
}
|
}
|
||||||
|
|
||||||
really_inline bool parse_number_with_space_terminated_copy(const bool is_negative) {
|
really_inline bool parse_number_with_space_terminated_copy() {
|
||||||
/**
|
/**
|
||||||
* We need to make a copy to make sure that the string is space terminated.
|
* We need to make a copy to make sure that the string is space terminated.
|
||||||
* This is not about padding the input, which should already padded up
|
* This is not about padding the input, which should already padded up
|
||||||
|
@ -190,7 +190,7 @@ struct structural_parser : structural_iterator {
|
||||||
memcpy(copy, buf, parser.len);
|
memcpy(copy, buf, parser.len);
|
||||||
memset(copy + parser.len, ' ', SIMDJSON_PADDING);
|
memset(copy + parser.len, ' ', SIMDJSON_PADDING);
|
||||||
size_t idx = *current_structural;
|
size_t idx = *current_structural;
|
||||||
bool result = parse_number(©[idx], is_negative); // parse_number does not throw
|
bool result = parse_number(©[idx]); // parse_number does not throw
|
||||||
free(copy);
|
free(copy);
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
@ -214,12 +214,10 @@ struct structural_parser : structural_iterator {
|
||||||
FAIL_IF( !atomparsing::is_valid_null_atom(current()) );
|
FAIL_IF( !atomparsing::is_valid_null_atom(current()) );
|
||||||
tape.append(0, internal::tape_type::NULL_VALUE);
|
tape.append(0, internal::tape_type::NULL_VALUE);
|
||||||
return continue_state;
|
return continue_state;
|
||||||
|
case '-':
|
||||||
case '0': case '1': case '2': case '3': case '4':
|
case '0': case '1': case '2': case '3': case '4':
|
||||||
case '5': case '6': case '7': case '8': case '9':
|
case '5': case '6': case '7': case '8': case '9':
|
||||||
FAIL_IF( parse_number(false) );
|
FAIL_IF( parse_number() );
|
||||||
return continue_state;
|
|
||||||
case '-':
|
|
||||||
FAIL_IF( parse_number(true) );
|
|
||||||
return continue_state;
|
return continue_state;
|
||||||
case '{':
|
case '{':
|
||||||
FAIL_IF( start_object(continue_state) );
|
FAIL_IF( start_object(continue_state) );
|
||||||
|
@ -375,18 +373,13 @@ WARN_UNUSED static error_code parse_structurals(dom_parser_implementation &dom_p
|
||||||
FAIL_IF( !atomparsing::is_valid_null_atom(parser.current(), parser.remaining_len()) );
|
FAIL_IF( !atomparsing::is_valid_null_atom(parser.current(), parser.remaining_len()) );
|
||||||
parser.tape.append(0, internal::tape_type::NULL_VALUE);
|
parser.tape.append(0, internal::tape_type::NULL_VALUE);
|
||||||
goto finish;
|
goto finish;
|
||||||
|
case '-':
|
||||||
case '0': case '1': case '2': case '3': case '4':
|
case '0': case '1': case '2': case '3': case '4':
|
||||||
case '5': case '6': case '7': case '8': case '9':
|
case '5': case '6': case '7': case '8': case '9':
|
||||||
// Next line used to be an interesting functional programming exercise with
|
// Next line used to be an interesting functional programming exercise with
|
||||||
// a lambda that gets passed to another function via a closure. This would confuse the
|
// a lambda that gets passed to another function via a closure. This would confuse the
|
||||||
// clangcl compiler under Visual Studio 2019 (recent release).
|
// clangcl compiler under Visual Studio 2019 (recent release).
|
||||||
{ if(parser.parse_number_with_space_terminated_copy(false)) { goto error; }}
|
FAIL_IF(parser.parse_number_with_space_terminated_copy());
|
||||||
goto finish;
|
|
||||||
case '-':
|
|
||||||
// Next line used to be an interesting functional programming exercise with
|
|
||||||
// a lambda that gets passed to another function via a closure. This would confuse the
|
|
||||||
// clangcl compiler under Visual Studio 2019 (recent release).
|
|
||||||
{ if(parser.parse_number_with_space_terminated_copy(true)) { goto error; }}
|
|
||||||
goto finish;
|
goto finish;
|
||||||
default:
|
default:
|
||||||
parser.log_error("Document starts with a non-value character");
|
parser.log_error("Document starts with a non-value character");
|
||||||
|
|
Loading…
Reference in New Issue