Skip to content

Commit 1035781

Browse files
authored
Avoid a clone when creating PrimitiveArray from ArrayData (#9190)
# Which issue does this PR close? - Part of #9061 - broken out of #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 #9114 # Are these changes tested? Existing tests # Are there any user-facing changes? No
1 parent be24e4f commit 1035781

File tree

1 file changed

+8
-5
lines changed

1 file changed

+8
-5
lines changed

arrow-array/src/array/primitive_array.rs

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1597,18 +1597,21 @@ impl<T: ArrowTimestampType> PrimitiveArray<T> {
15971597
/// Constructs a `PrimitiveArray` from an array data reference.
15981598
impl<T: ArrowPrimitiveType> From<ArrayData> for PrimitiveArray<T> {
15991599
fn from(data: ArrayData) -> Self {
1600-
Self::assert_compatible(data.data_type());
1600+
let (data_type, len, nulls, offset, mut buffers, _child_data) = data.into_parts();
1601+
1602+
Self::assert_compatible(&data_type);
16011603
assert_eq!(
1602-
data.buffers().len(),
1604+
buffers.len(),
16031605
1,
16041606
"PrimitiveArray data should contain a single buffer only (values buffer)"
16051607
);
1608+
let buffer = buffers.pop().expect("checked above");
16061609

1607-
let values = ScalarBuffer::new(data.buffers()[0].clone(), data.offset(), data.len());
1610+
let values = ScalarBuffer::new(buffer, offset, len);
16081611
Self {
1609-
data_type: data.data_type().clone(),
1612+
data_type,
16101613
values,
1611-
nulls: data.nulls().cloned(),
1614+
nulls,
16121615
}
16131616
}
16141617
}

0 commit comments

Comments
 (0)