From 59752fcba93f5eb4678230b5630b24856324824e Mon Sep 17 00:00:00 2001 From: mwish Date: Thu, 1 Feb 2024 21:24:42 +0800 Subject: [PATCH] GH-39845: [C++][Parquet] Minor: avoid creating a new Reader object in Decoder::SetData (#39847) ### Rationale for this change avoid creating a new Reader object in Decoder::SetData ### What changes are included in this PR? avoid creating a new Reader object in Decoder::SetData ### Are these changes tested? Already ### Are there any user-facing changes? no * Closes: #39845 Authored-by: mwish Signed-off-by: mwish --- cpp/src/parquet/encoding.cc | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/cpp/src/parquet/encoding.cc b/cpp/src/parquet/encoding.cc index b801b5ab11bb9..5573f5b9aed4c 100644 --- a/cpp/src/parquet/encoding.cc +++ b/cpp/src/parquet/encoding.cc @@ -2411,7 +2411,11 @@ class DeltaBitPackDecoder : public DecoderImpl, virtual public TypedDecodernum_values_ = num_values; - decoder_ = std::make_shared<::arrow::bit_util::BitReader>(data, len); + if (decoder_ == nullptr) { + decoder_ = std::make_shared<::arrow::bit_util::BitReader>(data, len); + } else { + decoder_->Reset(data, len); + } InitHeader(); } @@ -2769,7 +2773,11 @@ class DeltaLengthByteArrayDecoder : public DecoderImpl, void SetData(int num_values, const uint8_t* data, int len) override { DecoderImpl::SetData(num_values, data, len); - decoder_ = std::make_shared<::arrow::bit_util::BitReader>(data, len); + if (decoder_ == nullptr) { + decoder_ = std::make_shared<::arrow::bit_util::BitReader>(data, len); + } else { + decoder_->Reset(data, len); + } DecodeLengths(); }