Skip to content

Commit

Permalink
Minor: style enhancement for CompressedInputStream
Browse files Browse the repository at this point in the history
  • Loading branch information
mapleFU committed Dec 26, 2023
1 parent 2308cdf commit 0c49255
Showing 1 changed file with 7 additions and 11 deletions.
18 changes: 7 additions & 11 deletions cpp/src/arrow/io/compressed.cc
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ Result<std::shared_ptr<CompressedOutputStream>> CompressedOutputStream::Make(
util::Codec* codec, const std::shared_ptr<OutputStream>& raw, MemoryPool* pool) {
// CAUTION: codec is not owned
std::shared_ptr<CompressedOutputStream> res(new CompressedOutputStream);
res->impl_.reset(new Impl(pool, std::move(raw)));
res->impl_ = std::make_unique<Impl>(pool, std::move(raw));
RETURN_NOT_OK(res->impl_->Init(codec));
return res;
}
Expand Down Expand Up @@ -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);

Expand All @@ -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);
Expand All @@ -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;
Expand All @@ -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()) {
Expand Down Expand Up @@ -413,10 +410,9 @@ Result<std::shared_ptr<CompressedInputStream>> CompressedInputStream::Make(
Codec* codec, const std::shared_ptr<InputStream>& raw, MemoryPool* pool) {
// CAUTION: codec is not owned
std::shared_ptr<CompressedInputStream> res(new CompressedInputStream);
res->impl_.reset(new Impl(pool, std::move(raw)));
res->impl_ = std::make_unique<Impl>(pool, std::move(raw));
RETURN_NOT_OK(res->impl_->Init(codec));
return res;
return Status::OK();
}

CompressedInputStream::~CompressedInputStream() { internal::CloseFromDestructor(this); }
Expand Down

0 comments on commit 0c49255

Please sign in to comment.