This is an automated email from the ASF dual-hosted git repository.
dheres 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 1035781d68 Avoid a clone when creating `PrimitiveArray` from ArrayData
(#9190)
1035781d68 is described below
commit 1035781d68e384bb305295c38175b4adabc419aa
Author: Andrew Lamb <[email protected]>
AuthorDate: Thu Jan 15 12:45:36 2026 -0500
Avoid a clone when creating `PrimitiveArray` from ArrayData (#9190)
# Which issue does this PR close?
- Part of https://github.com/apache/arrow-rs/issues/9061
- broken out of https://github.com/apache/arrow-rs/pull/9058
# Rationale for this change
Let's make arrow-rs the fastest we can and the fewer allocations the
better
# What changes are included in this PR?
Apply pattern from https://github.com/apache/arrow-rs/pull/9114
# Are these changes tested?
Existing tests
# Are there any user-facing changes?
No
---
arrow-array/src/array/primitive_array.rs | 13 ++++++++-----
1 file changed, 8 insertions(+), 5 deletions(-)
diff --git a/arrow-array/src/array/primitive_array.rs
b/arrow-array/src/array/primitive_array.rs
index 87de5f6160..d49db8a7b2 100644
--- a/arrow-array/src/array/primitive_array.rs
+++ b/arrow-array/src/array/primitive_array.rs
@@ -1597,18 +1597,21 @@ impl<T: ArrowTimestampType> PrimitiveArray<T> {
/// Constructs a `PrimitiveArray` from an array data reference.
impl<T: ArrowPrimitiveType> From<ArrayData> for PrimitiveArray<T> {
fn from(data: ArrayData) -> Self {
- Self::assert_compatible(data.data_type());
+ let (data_type, len, nulls, offset, mut buffers, _child_data) =
data.into_parts();
+
+ Self::assert_compatible(&data_type);
assert_eq!(
- data.buffers().len(),
+ buffers.len(),
1,
"PrimitiveArray data should contain a single buffer only (values
buffer)"
);
+ let buffer = buffers.pop().expect("checked above");
- let values = ScalarBuffer::new(data.buffers()[0].clone(),
data.offset(), data.len());
+ let values = ScalarBuffer::new(buffer, offset, len);
Self {
- data_type: data.data_type().clone(),
+ data_type,
values,
- nulls: data.nulls().cloned(),
+ nulls,
}
}
}