Skip to content

Commit 1295fea

Browse files
authored
Avoid a clone when creating BooleanArray from ArrayData (#9159)
# 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 517b553 commit 1295fea

File tree

1 file changed

+7
-10
lines changed

1 file changed

+7
-10
lines changed

arrow-array/src/array/boolean_array.rs

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -389,24 +389,21 @@ impl From<Vec<Option<bool>>> for BooleanArray {
389389

390390
impl From<ArrayData> for BooleanArray {
391391
fn from(data: ArrayData) -> Self {
392+
let (data_type, len, nulls, offset, mut buffers, _child_data) = data.into_parts();
392393
assert_eq!(
393-
data.data_type(),
394-
&DataType::Boolean,
395-
"BooleanArray expected ArrayData with type {} got {}",
394+
data_type,
396395
DataType::Boolean,
397-
data.data_type()
396+
"BooleanArray expected ArrayData with type Boolean got {data_type:?}",
398397
);
399398
assert_eq!(
400-
data.buffers().len(),
399+
buffers.len(),
401400
1,
402401
"BooleanArray data should contain a single buffer only (values buffer)"
403402
);
404-
let values = BooleanBuffer::new(data.buffers()[0].clone(), data.offset(), data.len());
403+
let buffer = buffers.pop().expect("checked above");
404+
let values = BooleanBuffer::new(buffer, offset, len);
405405

406-
Self {
407-
values,
408-
nulls: data.nulls().cloned(),
409-
}
406+
Self { values, nulls }
410407
}
411408
}
412409

0 commit comments

Comments
 (0)