Skip to content

Commit 827be42

Browse files
authored
Avoid a clone when creating FixedSizeBinaryArray from ArrayData (#9186)
# 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 b64b458 commit 827be42

File tree

1 file changed

+9
-8
lines changed

1 file changed

+9
-8
lines changed

arrow-array/src/array/fixed_size_binary_array.rs

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -497,24 +497,25 @@ impl FixedSizeBinaryArray {
497497

498498
impl From<ArrayData> for FixedSizeBinaryArray {
499499
fn from(data: ArrayData) -> Self {
500+
let (data_type, len, nulls, offset, buffers, _child_data) = data.into_parts();
501+
500502
assert_eq!(
501-
data.buffers().len(),
503+
buffers.len(),
502504
1,
503505
"FixedSizeBinaryArray data should contain 1 buffer only (values)"
504506
);
505-
let value_length = match data.data_type() {
506-
DataType::FixedSizeBinary(len) => *len,
507+
let value_length = match data_type {
508+
DataType::FixedSizeBinary(len) => len,
507509
_ => panic!("Expected data type to be FixedSizeBinary"),
508510
};
509511

510512
let size = value_length as usize;
511-
let value_data =
512-
data.buffers()[0].slice_with_length(data.offset() * size, data.len() * size);
513+
let value_data = buffers[0].slice_with_length(offset * size, len * size);
513514

514515
Self {
515-
data_type: data.data_type().clone(),
516-
nulls: data.nulls().cloned(),
517-
len: data.len(),
516+
data_type,
517+
nulls,
518+
len,
518519
value_data,
519520
value_length,
520521
}

0 commit comments

Comments
 (0)