From c5ca63c6067fd08937b61e9e1c3f1a338033ad68 Mon Sep 17 00:00:00 2001 From: Nikita Mikhaylov Date: Wed, 25 Aug 2021 00:04:29 +0000 Subject: [PATCH] Fix performance (probably) --- src/Compression/LZ4_decompress_faster.cpp | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/Compression/LZ4_decompress_faster.cpp b/src/Compression/LZ4_decompress_faster.cpp index 52884e1e778..4a11d457f9a 100644 --- a/src/Compression/LZ4_decompress_faster.cpp +++ b/src/Compression/LZ4_decompress_faster.cpp @@ -475,7 +475,15 @@ bool NO_INLINE decompressImpl( return false; // Due to implementation specifics the copy length is always a multiple of copy_amount - const size_t real_length = std::max(copy_amount, static_cast(std::ceil(static_cast(length) / copy_amount) * copy_amount)); + size_t real_length = 0; + if constexpr (copy_amount == 8) + real_length = (((length >> 3) + 1) * 8); + else if constexpr (copy_amount == 16) + real_length = (((length >> 4) + 1) * 16); + else if constexpr (copy_amount == 32) + real_length = (((length >> 5) + 1) * 32); + else + throw std::runtime_error("Compile error!"); if (unlikely(ip + real_length >= input_end + ADDITIONAL_BYTES_AT_END_OF_BUFFER)) return false;