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

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


The following commit(s) were added to refs/heads/main by this push:
     new 2970e0f48f Replace BufferBuilder with Vec in sort_run_downcasted 
(#10630)
2970e0f48f is described below

commit 2970e0f48f390d29566e89b02820a7d315079056
Author: cakeni <[email protected]>
AuthorDate: Thu Aug 20 09:23:51 2026 +0800

    Replace BufferBuilder with Vec in sort_run_downcasted (#10630)
    
    # Which issue does this PR close?
    
    - Part of #10245.
    
    # Rationale for this change
    
    Using `Vec` instead of `BufferBuilder` can benefit from Rust's optimized
    vector implementation. This updates the remaining `BufferBuilder` usage
    in `arrow-ord/src/sort.rs`.
    
    # What changes are included in this PR?
    
    - Replace the run-end `BufferBuilder` in `sort_run_downcasted` with a
    preallocated `Vec`.
    - Push converted run ends directly into the vector and convert it into
    the final Arrow buffer.
    
    # Are these changes tested?
    
    Yes. The following checks pass:
    
    - `cargo +stable-x86_64-pc-windows-gnu fmt --all -- --check`
    - `cargo +stable-x86_64-pc-windows-gnu clippy -p arrow-ord --all-targets
    --all-features --no-deps -- -D warnings`
    - `cargo +stable-x86_64-pc-windows-gnu test -p arrow-ord --all-features`
    (269 unit tests and 6 doctests passed)
    
    # Are there any user-facing changes?
    
    No.
    
    ## AI assistance
    
    OpenAI Codex assisted with drafting this optimization. I reviewed and
    verified the final change.
    
    Co-authored-by: Jeffrey Vo <[email protected]>
---
 arrow-ord/src/sort.rs | 7 +++----
 1 file changed, 3 insertions(+), 4 deletions(-)

diff --git a/arrow-ord/src/sort.rs b/arrow-ord/src/sort.rs
index b814d4079f..c2629245bf 100644
--- a/arrow-ord/src/sort.rs
+++ b/arrow-ord/src/sort.rs
@@ -18,7 +18,6 @@
 //! Defines sort kernel for `ArrayRef`
 
 use crate::ord::{DynComparator, make_comparator};
-use arrow_array::builder::BufferBuilder;
 use arrow_array::cast::*;
 use arrow_array::types::*;
 use arrow_array::*;
@@ -722,14 +721,14 @@ fn sort_run_downcasted<R: RunEndIndexType>(
 
     let run_ends = run_array.run_ends();
 
-    let mut new_run_ends_builder = 
BufferBuilder::<R::Native>::new(run_ends.len());
+    let mut new_run_ends = Vec::with_capacity(run_ends.len());
     let mut new_run_end: usize = 0;
     let mut new_physical_len: usize = 0;
 
     let consume_runs = |run_length, _| {
         new_run_end += run_length;
         new_physical_len += 1;
-        
new_run_ends_builder.append(R::Native::from_usize(new_run_end).unwrap());
+        new_run_ends.push(R::Native::from_usize(new_run_end).unwrap());
     };
 
     let (values_indices, run_values) = sort_run_inner(run_array, options, 
output_len, consume_runs);
@@ -739,7 +738,7 @@ fn sort_run_downcasted<R: RunEndIndexType>(
         // The function builds a valid run_ends array and hence need not be 
validated.
         ArrayDataBuilder::new(R::DATA_TYPE)
             .len(new_physical_len)
-            .add_buffer(new_run_ends_builder.finish())
+            .add_buffer(new_run_ends.into())
             .build_unchecked()
     };
 

Reply via email to