diff --git a/src/IO/Lz4DeflatingWriteBuffer.cpp b/src/IO/Lz4DeflatingWriteBuffer.cpp index e952e6400ec..2dbb7f684ed 100644 --- a/src/IO/Lz4DeflatingWriteBuffer.cpp +++ b/src/IO/Lz4DeflatingWriteBuffer.cpp @@ -43,9 +43,6 @@ namespace { tmp_out.finalize(); - if (cur_out == sink) - return; - sink->write(tmp_out.buffer().begin(), tmp_out.count()); } @@ -67,8 +64,6 @@ namespace ErrorCodes Lz4DeflatingWriteBuffer::Lz4DeflatingWriteBuffer( std::unique_ptr out_, int compression_level, size_t buf_size, char * existing_memory, size_t alignment) : WriteBufferWithOwnMemoryDecorator(std::move(out_), buf_size, existing_memory, alignment) - , in_data(nullptr) - , in_capacity(0) , tmp_memory(buf_size) { @@ -106,9 +101,6 @@ void Lz4DeflatingWriteBuffer::nextImpl() if (!offset()) return; - in_data = reinterpret_cast(working_buffer.begin()); - in_capacity = offset(); - if (first_time) { auto sink = SinkToOut(out.get(), tmp_memory, LZ4F_HEADER_SIZE_MAX); @@ -128,7 +120,10 @@ void Lz4DeflatingWriteBuffer::nextImpl() first_time = false; } - do + auto in_data = working_buffer.begin(); + auto in_capacity = offset(); + + while (in_capacity > 0) { /// Ensure that there is enough space for compressed block of minimal size size_t min_compressed_block_size = LZ4F_compressBound(1, &kPrefs); @@ -154,11 +149,10 @@ void Lz4DeflatingWriteBuffer::nextImpl() LZ4F_VERSION, LZ4F_getErrorName(compressed_size), sink.getCapacity()); in_capacity -= cur_buffer_size; - in_data = reinterpret_cast(working_buffer.end() - in_capacity); + in_data += cur_buffer_size; sink.advancePosition(compressed_size); } - while (in_capacity > 0); } void Lz4DeflatingWriteBuffer::finalizeBefore() diff --git a/src/IO/Lz4DeflatingWriteBuffer.h b/src/IO/Lz4DeflatingWriteBuffer.h index 65f4f0c7349..7bb8a5e6c0e 100644 --- a/src/IO/Lz4DeflatingWriteBuffer.h +++ b/src/IO/Lz4DeflatingWriteBuffer.h @@ -32,9 +32,6 @@ private: LZ4F_preferences_t kPrefs; /// NOLINT LZ4F_compressionContext_t ctx; - void * in_data; - size_t in_capacity; - Memory<> tmp_memory; bool first_time = true;