Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 8 additions & 5 deletions arrow-array/src/array/primitive_array.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Copy link
Contributor Author

@alamb alamb Jan 15, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This saves a clone /call to DataType::drop as well as a Clone of Buffer (which is fairly inexpensive).

I don't think it will make any different in performance, but the code is cleaner and now consistent with other array types so I think this change is worth making

nulls,
}
}
}
Expand Down
Loading