This is an automated email from the ASF dual-hosted git repository. lihaopeng pushed a commit to branch vectorized in repository https://gitbox.apache.org/repos/asf/incubator-doris.git
commit 45286430724bfecaf73407f15c427aae6bd417e3 Author: Pxl <[email protected]> AuthorDate: Wed Jan 5 16:13:38 2022 +0800 [Bug] Change parser string to int (#7595) --- be/src/util/string_parser.hpp | 20 +++++++++++++++++ be/src/vec/io/io_helper.h | 52 ++++++------------------------------------- 2 files changed, 27 insertions(+), 45 deletions(-) diff --git a/be/src/util/string_parser.hpp b/be/src/util/string_parser.hpp index 0354343..cc1110c 100644 --- a/be/src/util/string_parser.hpp +++ b/be/src/util/string_parser.hpp @@ -573,6 +573,26 @@ T StringParser::numeric_limits(bool negative) { } template<> +inline int StringParser::StringParseTraits<uint8_t>::max_ascii_len() { + return 3; +} + +template<> +inline int StringParser::StringParseTraits<uint16_t>::max_ascii_len() { + return 5; +} + +template<> +inline int StringParser::StringParseTraits<uint32_t>::max_ascii_len() { + return 10; +} + +template<> +inline int StringParser::StringParseTraits<uint64_t>::max_ascii_len() { + return 20; +} + +template<> inline int StringParser::StringParseTraits<int8_t>::max_ascii_len() { return 3; } diff --git a/be/src/vec/io/io_helper.h b/be/src/vec/io/io_helper.h index fc232d7..fb9371f 100644 --- a/be/src/vec/io/io_helper.h +++ b/be/src/vec/io/io_helper.h @@ -126,7 +126,7 @@ inline void write_string_binary(const StringRef& s, BufferWritable& buf) { } inline void write_string_binary(const char* s, BufferWritable& buf) { - write_string_binary(StringRef{s}, buf); + write_string_binary(StringRef {s}, buf); } template <typename Type> @@ -288,53 +288,15 @@ bool read_float_text_fast_impl(T& x, ReadBuffer& in) { template <typename T> bool read_int_text_impl(T& x, ReadBuffer& buf) { - bool negative = false; - std::make_unsigned_t<T> res = 0; - if (buf.eof()) { - return false; - } + StringParser::ParseResult result; + x = StringParser::string_to_int<T>(buf.position(), buf.count(), &result); - while (!buf.eof()) { - switch (*buf.position()) { - case '+': - break; - case '-': - if (std::is_signed_v<T>) - negative = true; - else { - return false; - } - break; - case '0': - [[fallthrough]]; - case '1': - [[fallthrough]]; - case '2': - [[fallthrough]]; - case '3': - [[fallthrough]]; - case '4': - [[fallthrough]]; - case '5': - [[fallthrough]]; - case '6': - [[fallthrough]]; - case '7': - [[fallthrough]]; - case '8': - [[fallthrough]]; - case '9': - res *= 10; - res += *buf.position() - '0'; - break; - default: - x = negative ? -res : res; - return true; - } - ++buf.position(); + if (UNLIKELY(result != StringParser::PARSE_SUCCESS)) { + return false; } - x = negative ? -res : res; + // only to match the is_all_read() check to prevent return null + buf.position() = buf.end(); return true; } --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
