mirror of
https://github.com/ClickHouse/ClickHouse.git
synced 2024-11-24 08:32:02 +00:00
dbms: removed useless copy [#CONV-2546].
This commit is contained in:
parent
e60253110a
commit
f488fbbff5
@ -21,54 +21,34 @@ private:
|
||||
ReadBuffer & in;
|
||||
|
||||
std::vector<char> compressed_buffer;
|
||||
std::vector<char> decompressed_buffer;
|
||||
char scratch[QLZ_SCRATCH_DECOMPRESS];
|
||||
|
||||
size_t pos_in_buffer;
|
||||
|
||||
public:
|
||||
CompressedReadBuffer(ReadBuffer & in_)
|
||||
: in(in_),
|
||||
compressed_buffer(QUICKLZ_HEADER_SIZE),
|
||||
pos_in_buffer(0)
|
||||
compressed_buffer(QUICKLZ_HEADER_SIZE)
|
||||
{
|
||||
}
|
||||
|
||||
/** Читает и разжимает следующий кусок сжатых данных. */
|
||||
void readCompressedChunk()
|
||||
bool next()
|
||||
{
|
||||
if (in.eof())
|
||||
return false;
|
||||
|
||||
in.readStrict(&compressed_buffer[0], QUICKLZ_HEADER_SIZE);
|
||||
|
||||
size_t size_compressed = qlz_size_compressed(&compressed_buffer[0]);
|
||||
size_t size_decompressed = qlz_size_decompressed(&compressed_buffer[0]);
|
||||
|
||||
compressed_buffer.resize(size_compressed);
|
||||
decompressed_buffer.resize(size_decompressed);
|
||||
internal_buffer.resize(size_decompressed);
|
||||
|
||||
in.readStrict(&compressed_buffer[QUICKLZ_HEADER_SIZE], size_compressed - QUICKLZ_HEADER_SIZE);
|
||||
|
||||
qlz_decompress(&compressed_buffer[0], &decompressed_buffer[0], scratch);
|
||||
qlz_decompress(&compressed_buffer[0], &internal_buffer[0], scratch);
|
||||
|
||||
pos_in_buffer = 0;
|
||||
}
|
||||
|
||||
bool next()
|
||||
{
|
||||
if (pos_in_buffer == decompressed_buffer.size())
|
||||
{
|
||||
if (in.eof())
|
||||
return false;
|
||||
|
||||
readCompressedChunk();
|
||||
}
|
||||
|
||||
size_t bytes_to_copy = std::min(decompressed_buffer.size() - pos_in_buffer,
|
||||
static_cast<size_t>(DEFAULT_READ_BUFFER_SIZE));
|
||||
std::memcpy(working_buffer.begin(), &decompressed_buffer[pos_in_buffer], bytes_to_copy);
|
||||
|
||||
pos_in_buffer += bytes_to_copy;
|
||||
pos = working_buffer.begin();
|
||||
working_buffer = Buffer(working_buffer.begin(), working_buffer.begin() + bytes_to_copy);
|
||||
working_buffer = Buffer(working_buffer.begin(), working_buffer.begin() + size_decompressed);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user