mirror of
https://github.com/ClickHouse/ClickHouse.git
synced 2024-12-11 17:02:25 +00:00
Merge pull request #72715 from Algunenano/dragonbox
Remove heavy header from WriteHelpers.h
This commit is contained in:
commit
009580edd0
@ -3,6 +3,7 @@
|
||||
#include <Columns/ColumnString.h>
|
||||
#include <Columns/ColumnVector.h>
|
||||
#include <Columns/ColumnsNumber.h>
|
||||
#include <Core/UUID.h>
|
||||
#include <DataTypes/DataTypeString.h>
|
||||
#include <Functions/FunctionFactory.h>
|
||||
#include <Functions/IFunction.h>
|
||||
|
@ -1,13 +1,22 @@
|
||||
#include <IO/WriteHelpers.h>
|
||||
#include <cinttypes>
|
||||
#include <utility>
|
||||
#include <Common/formatIPv6.h>
|
||||
#include <base/DecomposedFloat.h>
|
||||
#include <base/hex.h>
|
||||
#include <Common/formatIPv6.h>
|
||||
|
||||
#pragma clang diagnostic push
|
||||
#pragma clang diagnostic ignored "-Wunused-parameter"
|
||||
#pragma clang diagnostic ignored "-Wsign-compare"
|
||||
#include <dragonbox/dragonbox_to_chars.h>
|
||||
#pragma clang diagnostic pop
|
||||
|
||||
namespace DB
|
||||
{
|
||||
|
||||
namespace ErrorCodes
|
||||
{
|
||||
extern const int CANNOT_PRINT_FLOAT_OR_DOUBLE_NUMBER;
|
||||
}
|
||||
|
||||
template <typename IteratorSrc, typename IteratorDst>
|
||||
void formatHex(IteratorSrc src, IteratorDst dst, size_t num_bytes)
|
||||
{
|
||||
@ -127,4 +136,38 @@ String fourSpaceIndent(size_t indent)
|
||||
{
|
||||
return std::string(indent * 4, ' ');
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
requires is_floating_point<T>
|
||||
size_t writeFloatTextFastPath(T x, char * buffer)
|
||||
{
|
||||
Int64 result = 0;
|
||||
|
||||
if constexpr (std::is_same_v<T, Float64>)
|
||||
{
|
||||
/// The library dragonbox has low performance on integers.
|
||||
/// This workaround improves performance 6..10 times.
|
||||
|
||||
if (DecomposedFloat64(x).isIntegerInRepresentableRange())
|
||||
result = itoa(Int64(x), buffer) - buffer;
|
||||
else
|
||||
result = jkj::dragonbox::to_chars_n(x, buffer) - buffer;
|
||||
}
|
||||
else if constexpr (std::is_same_v<T, Float32> || std::is_same_v<T, BFloat16>)
|
||||
{
|
||||
Float32 f32 = Float32(x);
|
||||
if (DecomposedFloat32(f32).isIntegerInRepresentableRange())
|
||||
result = itoa(Int32(f32), buffer) - buffer;
|
||||
else
|
||||
result = jkj::dragonbox::to_chars_n(f32, buffer) - buffer;
|
||||
}
|
||||
|
||||
if (result <= 0)
|
||||
throw Exception(ErrorCodes::CANNOT_PRINT_FLOAT_OR_DOUBLE_NUMBER, "Cannot print floating point number");
|
||||
return result;
|
||||
}
|
||||
|
||||
template size_t writeFloatTextFastPath(Float64 x, char * buffer);
|
||||
template size_t writeFloatTextFastPath(Float32 x, char * buffer);
|
||||
template size_t writeFloatTextFastPath(BFloat16 x, char * buffer);
|
||||
}
|
||||
|
@ -4,8 +4,6 @@
|
||||
#include <cstdio>
|
||||
#include <limits>
|
||||
#include <algorithm>
|
||||
#include <iterator>
|
||||
#include <concepts>
|
||||
#include <bit>
|
||||
|
||||
#include <pcg-random/pcg_random.hpp>
|
||||
@ -18,19 +16,14 @@
|
||||
#include <Common/transformEndianness.h>
|
||||
#include <base/find_symbols.h>
|
||||
#include <base/StringRef.h>
|
||||
#include <base/DecomposedFloat.h>
|
||||
|
||||
#include <Core/DecimalFunctions.h>
|
||||
#include <Core/Types.h>
|
||||
#include <Core/UUID.h>
|
||||
#include <base/IPv4andIPv6.h>
|
||||
|
||||
#include <Common/Exception.h>
|
||||
#include <Common/StringUtils.h>
|
||||
#include <Common/NaNUtils.h>
|
||||
#include <Common/typeid_cast.h>
|
||||
|
||||
#include <IO/CompressionMethod.h>
|
||||
#include <IO/WriteBuffer.h>
|
||||
#include <IO/WriteIntText.h>
|
||||
#include <IO/VarInt.h>
|
||||
@ -38,24 +31,11 @@
|
||||
#include <IO/WriteBufferFromString.h>
|
||||
#include <IO/WriteBufferFromFileDescriptor.h>
|
||||
|
||||
#pragma clang diagnostic push
|
||||
#pragma clang diagnostic ignored "-Wunused-parameter"
|
||||
#pragma clang diagnostic ignored "-Wsign-compare"
|
||||
#include <dragonbox/dragonbox_to_chars.h>
|
||||
#pragma clang diagnostic pop
|
||||
|
||||
#include <Formats/FormatSettings.h>
|
||||
|
||||
|
||||
namespace DB
|
||||
{
|
||||
|
||||
namespace ErrorCodes
|
||||
{
|
||||
extern const int CANNOT_PRINT_FLOAT_OR_DOUBLE_NUMBER;
|
||||
}
|
||||
|
||||
|
||||
/// Helper functions for formatted and binary output.
|
||||
|
||||
inline void writeChar(char x, WriteBuffer & buf)
|
||||
@ -151,41 +131,11 @@ inline void writeBoolText(bool x, WriteBuffer & buf)
|
||||
|
||||
template <typename T>
|
||||
requires is_floating_point<T>
|
||||
inline size_t writeFloatTextFastPath(T x, char * buffer)
|
||||
{
|
||||
Int64 result = 0;
|
||||
size_t writeFloatTextFastPath(T x, char * buffer);
|
||||
|
||||
if constexpr (std::is_same_v<T, Float64>)
|
||||
{
|
||||
/// The library Ryu has low performance on integers.
|
||||
/// This workaround improves performance 6..10 times.
|
||||
|
||||
if (DecomposedFloat64(x).isIntegerInRepresentableRange())
|
||||
result = itoa(Int64(x), buffer) - buffer;
|
||||
else
|
||||
result = jkj::dragonbox::to_chars_n(x, buffer) - buffer;
|
||||
}
|
||||
else if constexpr (std::is_same_v<T, Float32>)
|
||||
{
|
||||
if (DecomposedFloat32(x).isIntegerInRepresentableRange())
|
||||
result = itoa(Int32(x), buffer) - buffer;
|
||||
else
|
||||
result = jkj::dragonbox::to_chars_n(x, buffer) - buffer;
|
||||
}
|
||||
else if constexpr (std::is_same_v<T, BFloat16>)
|
||||
{
|
||||
Float32 f32 = Float32(x);
|
||||
|
||||
if (DecomposedFloat32(f32).isIntegerInRepresentableRange())
|
||||
result = itoa(Int32(f32), buffer) - buffer;
|
||||
else
|
||||
result = jkj::dragonbox::to_chars_n(f32, buffer) - buffer;
|
||||
}
|
||||
|
||||
if (result <= 0)
|
||||
throw Exception(ErrorCodes::CANNOT_PRINT_FLOAT_OR_DOUBLE_NUMBER, "Cannot print floating point number");
|
||||
return result;
|
||||
}
|
||||
extern template size_t writeFloatTextFastPath(Float64 x, char * buffer);
|
||||
extern template size_t writeFloatTextFastPath(Float32 x, char * buffer);
|
||||
extern template size_t writeFloatTextFastPath(BFloat16 x, char * buffer);
|
||||
|
||||
template <typename T>
|
||||
requires is_floating_point<T>
|
||||
|
Loading…
Reference in New Issue
Block a user