diff --git a/be/src/util/string_parser.hpp b/be/src/util/string_parser.hpp index 0354343ed7757a..cc1110c7a28f22 100644 --- a/be/src/util/string_parser.hpp +++ b/be/src/util/string_parser.hpp @@ -572,6 +572,26 @@ T StringParser::numeric_limits(bool negative) { return negative ? std::numeric_limits::min() : std::numeric_limits::max(); } +template<> +inline int StringParser::StringParseTraits::max_ascii_len() { + return 3; +} + +template<> +inline int StringParser::StringParseTraits::max_ascii_len() { + return 5; +} + +template<> +inline int StringParser::StringParseTraits::max_ascii_len() { + return 10; +} + +template<> +inline int StringParser::StringParseTraits::max_ascii_len() { + return 20; +} + template<> inline int StringParser::StringParseTraits::max_ascii_len() { return 3; diff --git a/be/src/vec/io/io_helper.h b/be/src/vec/io/io_helper.h index fc232d75c0647b..fb9371f3fab426 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 @@ -288,53 +288,15 @@ bool read_float_text_fast_impl(T& x, ReadBuffer& in) { template bool read_int_text_impl(T& x, ReadBuffer& buf) { - bool negative = false; - std::make_unsigned_t res = 0; - if (buf.eof()) { - return false; - } + StringParser::ParseResult result; + x = StringParser::string_to_int(buf.position(), buf.count(), &result); - while (!buf.eof()) { - switch (*buf.position()) { - case '+': - break; - case '-': - if (std::is_signed_v) - 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; }