This is an automated email from the ASF dual-hosted git repository.
alamb 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 517b553835 Minor: try and avoid an allocation creating
`GenericByteViewArray` from `ArrayData` (#9156)
517b553835 is described below
commit 517b5538352a6065d6d3ad701da2951790106b26
Author: Andrew Lamb <[email protected]>
AuthorDate: Wed Jan 14 07:02:08 2026 -0500
Minor: try and avoid an allocation creating `GenericByteViewArray` from
`ArrayData` (#9156)
# Which issue does this PR close?
- part of https://github.com/apache/arrow-rs/issues/9061
- follow on https://github.com/apache/arrow-rs/pull/9114
# Rationale for this change
@scovich noted in
https://github.com/apache/arrow-rs/pull/9114#discussion_r2683051311 that
calling `Vec::remove` does an extra copy and that `Vec::from` doesn't
actually reuse the allocation the way I thought it did
# What changes are included in this PR?
Build the Arc for buffers directly
# Are these changes tested?
BY existing tests
# Are there any user-facing changes?
<!--
If there are user-facing changes then we may require documentation to be
updated before approving the PR.
If there are any breaking changes to public APIs, please call them out.
-->
---
arrow-array/src/array/byte_view_array.rs | 12 +++++++-----
1 file changed, 7 insertions(+), 5 deletions(-)
diff --git a/arrow-array/src/array/byte_view_array.rs
b/arrow-array/src/array/byte_view_array.rs
index ca8ddfbe2a..ab6f0cd2d6 100644
--- a/arrow-array/src/array/byte_view_array.rs
+++ b/arrow-array/src/array/byte_view_array.rs
@@ -988,14 +988,16 @@ impl<'a, T: ByteViewType + ?Sized> IntoIterator for &'a
GenericByteViewArray<T>
impl<T: ByteViewType + ?Sized> From<ArrayData> for GenericByteViewArray<T> {
fn from(data: ArrayData) -> Self {
- let (_data_type, len, nulls, offset, mut buffers, _child_data) =
data.into_parts();
- let views = buffers.remove(0); // need to maintain order of remaining
buffers
- let buffers = Arc::from(buffers);
- let views = ScalarBuffer::new(views, offset, len);
+ let (_data_type, len, nulls, offset, buffers, _child_data) =
data.into_parts();
+
+ let mut buffers = buffers.into_iter();
+ // first buffer is views, remaining are data buffers
+ let views = ScalarBuffer::new(buffers.next().unwrap(), offset, len);
+
Self {
data_type: T::DATA_TYPE,
views,
- buffers,
+ buffers: Arc::from_iter(buffers),
nulls,
phantom: Default::default(),
}