diff --git a/src/generic/stage2/numberparsing.h b/src/generic/stage2/numberparsing.h index 033c3c3e..ea93aa94 100644 --- a/src/generic/stage2/numberparsing.h +++ b/src/generic/stage2/numberparsing.h @@ -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. template really_inline bool parse_number(UNUSED const uint8_t *const src, - UNUSED bool found_minus, W &writer) { #ifdef SIMDJSON_SKIPNUMBERPARSING // for performance analysis, it is sometimes // useful to skip parsing writer.append_s64(0); // always write zero return true; // always succeeds #else - const char *p = reinterpret_cast(src); - bool negative = false; - if (found_minus) { - ++p; - negative = true; - } + + // + // Check for minus sign + // + bool negative = (*src == '-'); + const char *p = reinterpret_cast(src) + negative; // // 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); } ++p; + // If the integer starts with 0, just check that there are no more digits. if (i == 0) { - // If the integer starts with 0, just check that there are no more digits. if (static_cast(*p - '0') <= 9) { return INVALID_NUMBER(src); } // 0 cannot be followed by an integer } else { // Integer starts with 1-9. Parse the rest of the integer diff --git a/src/generic/stage2/structural_parser.h b/src/generic/stage2/structural_parser.h index 359026b7..d6ca1aca 100644 --- a/src/generic/stage2/structural_parser.h +++ b/src/generic/stage2/structural_parser.h @@ -159,17 +159,17 @@ struct structural_parser : structural_iterator { 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"); - bool succeeded = numberparsing::parse_number(src, found_minus, tape); + bool succeeded = numberparsing::parse_number(src, tape); if (!succeeded) { log_error("Invalid number"); } return !succeeded; } - WARN_UNUSED really_inline bool parse_number(bool found_minus) { - return parse_number(current(), found_minus); + WARN_UNUSED really_inline bool parse_number() { + 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. * 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); memset(copy + parser.len, ' ', SIMDJSON_PADDING); 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); return result; } @@ -214,12 +214,10 @@ struct structural_parser : structural_iterator { FAIL_IF( !atomparsing::is_valid_null_atom(current()) ); tape.append(0, internal::tape_type::NULL_VALUE); return continue_state; + case '-': case '0': case '1': case '2': case '3': case '4': case '5': case '6': case '7': case '8': case '9': - FAIL_IF( parse_number(false) ); - return continue_state; - case '-': - FAIL_IF( parse_number(true) ); + FAIL_IF( parse_number() ); return continue_state; case '{': 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()) ); parser.tape.append(0, internal::tape_type::NULL_VALUE); goto finish; + case '-': case '0': case '1': case '2': case '3': case '4': case '5': case '6': case '7': case '8': case '9': // 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(false)) { goto error; }} - 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; }} + FAIL_IF(parser.parse_number_with_space_terminated_copy()); goto finish; default: parser.log_error("Document starts with a non-value character");