diff --git a/src/Access/Common/QuotaDefs.cpp b/src/Access/Common/QuotaDefs.cpp index f9f8a56d534..66a374ed83d 100644 --- a/src/Access/Common/QuotaDefs.cpp +++ b/src/Access/Common/QuotaDefs.cpp @@ -1,13 +1,12 @@ #include #include - -#include +#include +#include #include #include #include #include -#include namespace DB @@ -29,15 +28,15 @@ String QuotaTypeInfo::valueToString(QuotaValue value) const if (!(value % output_denominator)) return std::to_string(value / output_denominator); else - return boost::lexical_cast(static_cast(value) / output_denominator); + return toString(static_cast(value) / output_denominator); } QuotaValue QuotaTypeInfo::stringToValue(const String & str) const { if (output_denominator == 1) - return static_cast(std::strtoul(str.c_str(), nullptr, 10)); + return static_cast(parse(str)); else - return static_cast(std::strtod(str.c_str(), nullptr) * output_denominator); + return static_cast(parse(str) * output_denominator); } String QuotaTypeInfo::valueToStringWithName(QuotaValue value) const diff --git a/src/IO/readFloatText.h b/src/IO/readFloatText.h index a72ff82008e..369ea4ab87c 100644 --- a/src/IO/readFloatText.h +++ b/src/IO/readFloatText.h @@ -144,7 +144,7 @@ bool assertOrParseNaN(ReadBuffer & buf) template ReturnType readFloatTextPreciseImpl(T & x, ReadBuffer & buf) { - static_assert(std::is_same_v || std::is_same_v, "Argument for readFloatTextFastFloatImpl must be float or double"); + static_assert(std::is_same_v || std::is_same_v, "Argument for readFloatTextPreciseImpl must be float or double"); static_assert('a' > '.' && 'A' > '.' && '\n' < '.' && '\t' < '.' && '\'' < '.' && '"' < '.', "Layout of char is not like ASCII"); //-V590 static constexpr bool throw_exception = std::is_same_v; diff --git a/src/Parsers/ExpressionElementParsers.cpp b/src/Parsers/ExpressionElementParsers.cpp index c6b51fd4dfe..23f016b7791 100644 --- a/src/Parsers/ExpressionElementParsers.cpp +++ b/src/Parsers/ExpressionElementParsers.cpp @@ -1,15 +1,14 @@ -#include -#include - #include #include #include -#include +#include + #include #include #include +#include #include #include #include @@ -29,22 +28,17 @@ #include #include #include - #include #include - - #include #include #include #include #include #include - #include #include #include - #include #include @@ -834,10 +828,9 @@ bool ParserNumber::parseImpl(Pos & pos, ASTPtr & node, Expected & expected) auto try_read_float = [&](const char * it, const char * end) { - char * str_end; - errno = 0; /// Functions strto* don't clear errno. - Float64 float_value = std::strtod(it, &str_end); - if (str_end == end && errno != ERANGE) + Float64 float_value = 0; + ReadBufferFromMemory buf(it, end - it); + if (tryReadFloatTextPrecise(float_value, buf)) { if (float_value < 0) throw Exception("Logical error: token number cannot begin with minus, but parsed float number is less than zero.", ErrorCodes::LOGICAL_ERROR); @@ -882,7 +875,10 @@ bool ParserNumber::parseImpl(Pos & pos, ASTPtr & node, Expected & expected) for (const auto * it = pos->begin; it != pos->end; ++it) { if (*it != '_') - buf[buf_size++] = *it; + { + buf[buf_size] = *it; + ++buf_size; + } if (unlikely(buf_size > MAX_LENGTH_OF_NUMBER)) { expected.add(pos, "number"); diff --git a/src/Processors/Formats/Impl/ConstantExpressionTemplate.cpp b/src/Processors/Formats/Impl/ConstantExpressionTemplate.cpp index 994af449947..9e7a5a9aa8f 100644 --- a/src/Processors/Formats/Impl/ConstantExpressionTemplate.cpp +++ b/src/Processors/Formats/Impl/ConstantExpressionTemplate.cpp @@ -553,7 +553,9 @@ bool ConstantExpressionTemplate::parseLiteralAndAssertType( { Field number; if (type_info.is_nullable && 4 <= istr.available() && 0 == strncasecmp(istr.position(), "NULL", 4)) + { istr.position() += 4; + } else { /// ParserNumber::parse(...) is about 20x slower than strtod(...)