mirror of
https://github.com/ClickHouse/ClickHouse.git
synced 2024-11-29 02:52:13 +00:00
Improve CompressedWriteBuffer to avoid unnecessary memcpy
This commit is contained in:
parent
9ad7f2d081
commit
2ae9e22248
@ -22,14 +22,29 @@ void CompressedWriteBuffer::nextImpl()
|
||||
if (!offset())
|
||||
return;
|
||||
|
||||
UInt32 compressed_size = 0;
|
||||
size_t decompressed_size = offset();
|
||||
UInt32 compressed_reserve_size = codec->getCompressedReserveSize(decompressed_size);
|
||||
compressed_buffer.resize(compressed_reserve_size);
|
||||
UInt32 compressed_size = codec->compress(working_buffer.begin(), decompressed_size, compressed_buffer.data());
|
||||
|
||||
if(out.available() > (compressed_reserve_size + CHECKSUM_SIZE))
|
||||
{
|
||||
char *out_checksum_ptr = out.position();
|
||||
char *out_compressed_ptr = out.position() + CHECKSUM_SIZE;
|
||||
compressed_size = codec->compress(working_buffer.begin(), decompressed_size, out_compressed_ptr);
|
||||
|
||||
CityHash_v1_0_2::uint128 checksum = CityHash_v1_0_2::CityHash128(compressed_buffer.data(), compressed_size);
|
||||
out.write(reinterpret_cast<const char *>(&checksum), CHECKSUM_SIZE);
|
||||
out.write(compressed_buffer.data(), compressed_size);
|
||||
CityHash_v1_0_2::uint128 checksum = CityHash_v1_0_2::CityHash128(out_compressed_ptr, compressed_size);
|
||||
memcpy(out_checksum_ptr, &checksum, CHECKSUM_SIZE);
|
||||
out.position() += CHECKSUM_SIZE + compressed_size;
|
||||
}
|
||||
else
|
||||
{
|
||||
compressed_buffer.resize(compressed_reserve_size);
|
||||
compressed_size = codec->compress(working_buffer.begin(), decompressed_size, compressed_buffer.data());
|
||||
|
||||
CityHash_v1_0_2::uint128 checksum = CityHash_v1_0_2::CityHash128(compressed_buffer.data(), compressed_size);
|
||||
out.write(reinterpret_cast<const char *>(&checksum), CHECKSUM_SIZE);
|
||||
out.write(compressed_buffer.data(), compressed_size);
|
||||
}
|
||||
}
|
||||
|
||||
CompressedWriteBuffer::~CompressedWriteBuffer()
|
||||
|
Loading…
Reference in New Issue
Block a user