Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions be/src/util/string_parser.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -572,6 +572,26 @@ T StringParser::numeric_limits(bool negative) {
return negative ? std::numeric_limits<T>::min() : std::numeric_limits<T>::max();
}

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;
Expand Down
52 changes: 7 additions & 45 deletions be/src/vec/io/io_helper.h
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand Down Expand Up @@ -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;
}

Expand Down