From f488fbbff57d033b4141ee77b373465b945a26c6 Mon Sep 17 00:00:00 2001 From: Alexey Milovidov Date: Fri, 17 Jun 2011 21:31:41 +0000 Subject: [PATCH] dbms: removed useless copy [#CONV-2546]. --- dbms/include/DB/IO/CompressedReadBuffer.h | 36 +++++------------------ 1 file changed, 8 insertions(+), 28 deletions(-) diff --git a/dbms/include/DB/IO/CompressedReadBuffer.h b/dbms/include/DB/IO/CompressedReadBuffer.h index 7d10e334a62..cc0fbbf072f 100644 --- a/dbms/include/DB/IO/CompressedReadBuffer.h +++ b/dbms/include/DB/IO/CompressedReadBuffer.h @@ -21,54 +21,34 @@ private: ReadBuffer & in; std::vector compressed_buffer; - std::vector 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); - 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(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; }