mirror of
https://github.com/ClickHouse/ClickHouse.git
synced 2024-11-21 15:12: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;
|
ReadBuffer & in;
|
||||||
|
|
||||||
std::vector<char> compressed_buffer;
|
std::vector<char> compressed_buffer;
|
||||||
std::vector<char> decompressed_buffer;
|
|
||||||
char scratch[QLZ_SCRATCH_DECOMPRESS];
|
char scratch[QLZ_SCRATCH_DECOMPRESS];
|
||||||
|
|
||||||
size_t pos_in_buffer;
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
CompressedReadBuffer(ReadBuffer & in_)
|
CompressedReadBuffer(ReadBuffer & in_)
|
||||||
: in(in_),
|
: in(in_),
|
||||||
compressed_buffer(QUICKLZ_HEADER_SIZE),
|
compressed_buffer(QUICKLZ_HEADER_SIZE)
|
||||||
pos_in_buffer(0)
|
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Читает и разжимает следующий кусок сжатых данных. */
|
bool next()
|
||||||
void readCompressedChunk()
|
|
||||||
{
|
{
|
||||||
|
if (in.eof())
|
||||||
|
return false;
|
||||||
|
|
||||||
in.readStrict(&compressed_buffer[0], QUICKLZ_HEADER_SIZE);
|
in.readStrict(&compressed_buffer[0], QUICKLZ_HEADER_SIZE);
|
||||||
|
|
||||||
size_t size_compressed = qlz_size_compressed(&compressed_buffer[0]);
|
size_t size_compressed = qlz_size_compressed(&compressed_buffer[0]);
|
||||||
size_t size_decompressed = qlz_size_decompressed(&compressed_buffer[0]);
|
size_t size_decompressed = qlz_size_decompressed(&compressed_buffer[0]);
|
||||||
|
|
||||||
compressed_buffer.resize(size_compressed);
|
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);
|
in.readStrict(&compressed_buffer[QUICKLZ_HEADER_SIZE], size_compressed - QUICKLZ_HEADER_SIZE);
|
||||||
|
|
||||||
qlz_decompress(&compressed_buffer[0], &decompressed_buffer[0], scratch);
|
|
||||||
|
|
||||||
pos_in_buffer = 0;
|
qlz_decompress(&compressed_buffer[0], &internal_buffer[0], scratch);
|
||||||
}
|
|
||||||
|
|
||||||
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();
|
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;
|
return true;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user