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 9232202a5f Replace substring BufferBuilders with Vec (#10634)
9232202a5f is described below
commit 9232202a5fdac5e4aff69694fc3daf095eca6c4a
Author: cakeni <[email protected]>
AuthorDate: Thu Aug 20 09:23:16 2026 +0800
Replace substring BufferBuilders with Vec (#10634)
# Which issue does this PR close?
Part of #10245.
# Rationale for this change
`Vec` provides the same capacity preallocation and append behavior
needed by `substring_by_char_impl` without the additional
`BufferBuilder` abstraction.
# What changes are included in this PR?
- Replace the byte-value `BufferBuilder` with `Vec<u8>`.
- Replace the offset `BufferBuilder` with `Vec<OffsetSize>`.
- Preserve the existing capacity estimates, null handling, and offset
construction.
# Are there any user-facing changes?
No.
# How was this change tested?
- `cargo +stable-x86_64-pc-windows-gnu fmt --all -- --check`
- `cargo +stable-x86_64-pc-windows-gnu clippy -p arrow-string
--all-targets --all-features --no-deps -- -D warnings`
- `cargo +stable-x86_64-pc-windows-gnu test -p arrow-string
--all-features` (182 unit tests and 10 doc tests passed)
## AI assistance
OpenAI Codex assisted with code exploration and drafting this change. I
reviewed the final diff and ran the checks listed above.
Co-authored-by: Jefffrey <[email protected]>
---
arrow-string/src/substring.rs | 16 ++++++++--------
1 file changed, 8 insertions(+), 8 deletions(-)
diff --git a/arrow-string/src/substring.rs b/arrow-string/src/substring.rs
index 2169f63f25..6422f7b167 100644
--- a/arrow-string/src/substring.rs
+++ b/arrow-string/src/substring.rs
@@ -20,7 +20,7 @@
//! [GenericStringArray], [GenericBinaryArray], [GenericByteViewArray],
//! [FixedSizeBinaryArray], [DictionaryArray]
-use arrow_array::builder::{BinaryViewBuilder, BufferBuilder,
StringViewBuilder};
+use arrow_array::builder::{BinaryViewBuilder, StringViewBuilder};
use arrow_array::cast::AsArray;
use arrow_array::types::*;
use arrow_array::*;
@@ -172,7 +172,7 @@ fn substring_by_char_impl<OffsetSize: OffsetSizeTrait, F:
Fn(&str) -> (usize, us
max_element_len: Option<usize>,
bounds: F,
) -> GenericStringArray<OffsetSize> {
- let mut vals = BufferBuilder::<u8>::new({
+ let mut vals = Vec::with_capacity({
let offsets = array.value_offsets();
let input_len = (offsets[array.len()] -
offsets[0]).to_usize().unwrap();
match max_element_len {
@@ -180,19 +180,19 @@ fn substring_by_char_impl<OffsetSize: OffsetSizeTrait, F:
Fn(&str) -> (usize, us
None => input_len,
}
});
- let mut new_offsets = BufferBuilder::<OffsetSize>::new(array.len() + 1);
- new_offsets.append(OffsetSize::zero());
+ let mut new_offsets = Vec::with_capacity(array.len() + 1);
+ new_offsets.push(OffsetSize::zero());
array.iter().for_each(|val| {
if let Some(val) = val {
let (start_offset, end_offset) = bounds(val);
- vals.append_slice(&val.as_bytes()[start_offset..end_offset]);
+ vals.extend_from_slice(&val.as_bytes()[start_offset..end_offset]);
}
- new_offsets.append(OffsetSize::from_usize(vals.len()).unwrap());
+ new_offsets.push(OffsetSize::from_usize(vals.len()).unwrap());
});
- let offsets = OffsetBuffer::new(new_offsets.finish().into());
- let values = vals.finish();
+ let offsets = OffsetBuffer::new(new_offsets.into());
+ let values = vals.into();
let nulls = array
.nulls()
.map(|n| n.inner().sliced())