提交 e8385f67 编写于 作者: A Alexey Milovidov

Addition to prev. revision #1665

上级 b7b3b6fc
...@@ -190,45 +190,29 @@ ReturnType readFloatTextPreciseImpl(T & x, ReadBuffer & buf) ...@@ -190,45 +190,29 @@ ReturnType readFloatTextPreciseImpl(T & x, ReadBuffer & buf)
template <size_t N, typename T> template <size_t N, typename T>
void readIntTextUpToNChars(T & x, ReadBuffer & buf) void readIntTextUpToNChars(T & x, ReadBuffer & buf)
{ {
if (unlikely(buf.eof()))
return;
bool negative = false; bool negative = false;
x = 0;
if (std::is_signed_v<T> && *buf.position() == '-')
{
++buf.position();
negative = true;
}
for (size_t i = 0; !buf.eof(); ++i) for (size_t i = 0; !buf.eof(); ++i)
{ {
switch (*buf.position()) if ((*buf.position() & 0xF0) == 0x30)
{ {
case '+': x *= 10;
break; x += *buf.position() & 0x0F;
case '-': ++buf.position();
if (std::is_signed_v<T>)
negative = true;
else
throw Exception("Unsigned type must not contain '-' symbol", ErrorCodes::CANNOT_PARSE_NUMBER);
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':
if (i < N)
{
x *= 10;
x += *buf.position() - '0';
}
break;
default:
if (negative)
x = -x;
return;
} }
++buf.position(); else
break;
} }
if (negative) if (std::is_signed_v<T> && negative)
x = -x; x = -x;
} }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册