From b30566ab3ddcd3def86e889c0be9617cdf90dab5 Mon Sep 17 00:00:00 2001 From: Judah Rand <17158624+judahrand@users.noreply.github.com> Date: Wed, 12 Jun 2024 09:58:14 +0100 Subject: [PATCH] Avoid a `Box::new()` when not needed --- arrow-select/src/concat.rs | 28 ++++++++++++++++++++-------- 1 file changed, 20 insertions(+), 8 deletions(-) diff --git a/arrow-select/src/concat.rs b/arrow-select/src/concat.rs index 6096dc082251..7eaa125319d0 100644 --- a/arrow-select/src/concat.rs +++ b/arrow-select/src/concat.rs @@ -57,14 +57,26 @@ fn binary_capacity(arrays: &[&dyn Array]) -> Capacities { fn fixed_size_list_capacity(arrays: &[&dyn Array], data_type: &DataType) -> Capacities { if let DataType::FixedSizeList(f, _) = data_type { let item_capacity = arrays.iter().map(|a| a.len()).sum(); - let values: Vec<&dyn arrow_array::Array> = arrays - .iter() - .map(|a| a.as_fixed_size_list().values().as_ref()) - .collect(); - Capacities::List( - item_capacity, - Some(Box::new(get_capacity(&values, f.data_type()))), - ) + let child_data_type = f.data_type(); + match child_data_type { + // These types should match the types that `get_capacity` + // has special handling for. + DataType::Utf8 + | DataType::LargeUtf8 + | DataType::Binary + | DataType::LargeBinary + | DataType::FixedSizeList(_, _) => { + let values: Vec<&dyn arrow_array::Array> = arrays + .iter() + .map(|a| a.as_fixed_size_list().values().as_ref()) + .collect(); + Capacities::List( + item_capacity, + Some(Box::new(get_capacity(&values, child_data_type))), + ) + }, + _ => Capacities::Array(item_capacity), + } } else { unreachable!("illegal data type for fixed size list") }