This is an automated email from the ASF dual-hosted git repository.

maplefu pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/arrow.git


The following commit(s) were added to refs/heads/main by this push:
     new 2721134715 GH-39845: [C++][Parquet] Minor: avoid creating a new Reader 
object in Decoder::SetData (#39847)
2721134715 is described below

commit 2721134715b7dedfa2715bcf47548728ff702d5a
Author: mwish <[email protected]>
AuthorDate: Thu Feb 1 21:24:42 2024 +0800

    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 <[email protected]>
    Signed-off-by: mwish <[email protected]>
---
 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 b801b5ab11..5573f5b9ae 100644
--- a/cpp/src/parquet/encoding.cc
+++ b/cpp/src/parquet/encoding.cc
@@ -2411,7 +2411,11 @@ class DeltaBitPackDecoder : public DecoderImpl, virtual 
public TypedDecoder<DTyp
   void SetData(int num_values, const uint8_t* data, int len) override {
     // num_values is equal to page's num_values, including null values in this 
page
     this->num_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();
   }
 

Reply via email to