From 0c49255d5290c3795cd3a43bf1514cceacb9a2e8 Mon Sep 17 00:00:00 2001 From: mwish Date: Tue, 26 Dec 2023 19:35:08 +0800 Subject: [PATCH] Minor: style enhancement for CompressedInputStream --- cpp/src/arrow/io/compressed.cc | 18 +++++++----------- 1 file changed, 7 insertions(+), 11 deletions(-) diff --git a/cpp/src/arrow/io/compressed.cc b/cpp/src/arrow/io/compressed.cc index 6c484242a4fc8..39f90e8bc6246 100644 --- a/cpp/src/arrow/io/compressed.cc +++ b/cpp/src/arrow/io/compressed.cc @@ -201,7 +201,7 @@ Result> CompressedOutputStream::Make( util::Codec* codec, const std::shared_ptr& raw, MemoryPool* pool) { // CAUTION: codec is not owned std::shared_ptr res(new CompressedOutputStream); - res->impl_.reset(new Impl(pool, std::move(raw))); + res->impl_ = std::make_unique(pool, std::move(raw)); RETURN_NOT_OK(res->impl_->Init(codec)); return res; } @@ -277,7 +277,7 @@ class CompressedInputStream::Impl { } // Decompress some data from the compressed_ buffer. - // Call this function only if the decompressed_ buffer is empty. + // Call this function only if the decompressed_ buffer is empty or exhausted. Status DecompressData() { DCHECK_NE(compressed_->data(), nullptr); @@ -300,7 +300,8 @@ class CompressedInputStream::Impl { fresh_decompressor_ = false; } if (result.bytes_written > 0 || !result.need_more_output || input_len == 0) { - RETURN_NOT_OK(decompressed_->Resize(result.bytes_written)); + RETURN_NOT_OK( + decompressed_->Resize(result.bytes_written, /*shrink_to_fit=*/false)); break; } DCHECK_EQ(result.bytes_written, 0); @@ -318,11 +319,6 @@ class CompressedInputStream::Impl { if (read_bytes > 0) { memcpy(out, decompressed_->data() + decompressed_pos_, read_bytes); decompressed_pos_ += read_bytes; - - if (decompressed_pos_ == decompressed_->size()) { - // Decompressed data is exhausted, release buffer - decompressed_.reset(); - } } return read_bytes; @@ -339,7 +335,8 @@ class CompressedInputStream::Impl { } RETURN_NOT_OK(DecompressData()); } - if (!decompressed_ || decompressed_->size() == 0) { + if (decompressed_ == nullptr || decompressed_->size() == 0 || + decompressed_->size() == decompressed_pos_) { // Got nothing, need to read more compressed data RETURN_NOT_OK(EnsureCompressedData()); if (compressed_pos_ == compressed_->size()) { @@ -413,10 +410,9 @@ Result> CompressedInputStream::Make( Codec* codec, const std::shared_ptr& raw, MemoryPool* pool) { // CAUTION: codec is not owned std::shared_ptr res(new CompressedInputStream); - res->impl_.reset(new Impl(pool, std::move(raw))); + res->impl_ = std::make_unique(pool, std::move(raw)); RETURN_NOT_OK(res->impl_->Init(codec)); return res; - return Status::OK(); } CompressedInputStream::~CompressedInputStream() { internal::CloseFromDestructor(this); }