From 64549702a2c693356800571da8ceb8ec5bc6f27b Mon Sep 17 00:00:00 2001 From: Maksim Kita Date: Sun, 6 Dec 2020 00:32:03 +0300 Subject: [PATCH] DragonBox integration --- .gitmodules | 3 +++ contrib/CMakeLists.txt | 2 ++ contrib/dragonbox | 1 + docker/test/fasttest/run.sh | 1 + src/CMakeLists.txt | 1 + src/IO/WriteHelpers.h | 6 +++--- src/IO/tests/CMakeLists.txt | 1 + src/IO/tests/ryu_test.cpp | 7 ++++++- 8 files changed, 18 insertions(+), 4 deletions(-) create mode 160000 contrib/dragonbox diff --git a/.gitmodules b/.gitmodules index b9a22d13c79..f9c8c191b00 100644 --- a/.gitmodules +++ b/.gitmodules @@ -209,3 +209,6 @@ path = contrib/abseil-cpp url = https://github.com/ClickHouse-Extras/abseil-cpp.git branch = lts_2020_02_25 +[submodule "contrib/dragonbox"] + path = contrib/dragonbox + url = https://github.com/kitaisreal/dragonbox.git diff --git a/contrib/CMakeLists.txt b/contrib/CMakeLists.txt index 57f08cc399c..2b799974b73 100644 --- a/contrib/CMakeLists.txt +++ b/contrib/CMakeLists.txt @@ -322,3 +322,5 @@ endif() if (USE_INTERNAL_ROCKSDB_LIBRARY) add_subdirectory(rocksdb-cmake) endif() + +add_subdirectory(dragonbox) \ No newline at end of file diff --git a/contrib/dragonbox b/contrib/dragonbox new file mode 160000 index 00000000000..17d07b00f9c --- /dev/null +++ b/contrib/dragonbox @@ -0,0 +1 @@ +Subproject commit 17d07b00f9c70d61c60c3bd1046c2ef6814d14c6 diff --git a/docker/test/fasttest/run.sh b/docker/test/fasttest/run.sh index 63c3c679668..7cef484e9f2 100755 --- a/docker/test/fasttest/run.sh +++ b/docker/test/fasttest/run.sh @@ -155,6 +155,7 @@ function clone_submodules contrib/croaring contrib/miniselect contrib/xz + contrib/dragonbox ) git submodule sync diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index e1ca1729081..bf693a02a3a 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -243,6 +243,7 @@ target_link_libraries (clickhouse_common_io common ${DOUBLE_CONVERSION_LIBRARIES} ryu + dragonbox_to_chars ) if(RE2_LIBRARY) diff --git a/src/IO/WriteHelpers.h b/src/IO/WriteHelpers.h index 201dbb30a86..1997aede564 100644 --- a/src/IO/WriteHelpers.h +++ b/src/IO/WriteHelpers.h @@ -29,7 +29,7 @@ #include #include -#include +#include #include @@ -228,14 +228,14 @@ inline size_t writeFloatTextFastPath(T x, char * buffer) if (DecomposedFloat64(x).is_inside_int64()) result = itoa(Int64(x), buffer) - buffer; else - result = d2s_buffered_n(x, buffer); + result = jkj::dragonbox::to_chars_n(x, buffer) - buffer; } else { if (DecomposedFloat32(x).is_inside_int32()) result = itoa(Int32(x), buffer) - buffer; else - result = f2s_buffered_n(x, buffer); + result = jkj::dragonbox::to_chars_n(x, buffer) - buffer; } if (result <= 0) diff --git a/src/IO/tests/CMakeLists.txt b/src/IO/tests/CMakeLists.txt index 77dfd5404c7..994eed0f737 100644 --- a/src/IO/tests/CMakeLists.txt +++ b/src/IO/tests/CMakeLists.txt @@ -82,6 +82,7 @@ target_link_libraries (zlib_ng_bug PRIVATE ${ZLIB_LIBRARIES}) add_executable (ryu_test ryu_test.cpp) target_link_libraries (ryu_test PRIVATE ryu) +target_link_libraries (ryu_test PRIVATE dragonbox_to_chars) add_executable (zstd_buffers zstd_buffers.cpp) target_link_libraries (zstd_buffers PRIVATE clickhouse_common_io) diff --git a/src/IO/tests/ryu_test.cpp b/src/IO/tests/ryu_test.cpp index 503eec82fd6..e99be60e7b5 100644 --- a/src/IO/tests/ryu_test.cpp +++ b/src/IO/tests/ryu_test.cpp @@ -2,7 +2,7 @@ #include #include #include - +#include struct DecomposedFloat64 { @@ -84,9 +84,14 @@ int main(int argc, char ** argv) double x = argc > 1 ? std::stod(argv[1]) : 0; char buf[32]; + std::cout << "ryu output" << std::endl; d2s_buffered(x, buf); std::cout << buf << "\n"; + std::cout << "dragonbox output" << std::endl; + jkj::dragonbox::to_chars(x, buf); + std::cout << buf << "\n"; + std::cout << DecomposedFloat64(x).isInsideInt64() << "\n"; return 0;