From 31d57b8db3c17c57288a4ae267e5def1a6a9a6e7 Mon Sep 17 00:00:00 2001 From: Simon Vandel Sillesen Date: Sat, 30 Oct 2021 23:17:25 +0200 Subject: [PATCH] Avoid unnecessary allocations (#559) * Avoid unnecessary to_string allocations * Only get displayer for the interesting field --- src/array/display.rs | 7 +------ src/ffi/schema.rs | 8 ++++---- 2 files changed, 5 insertions(+), 10 deletions(-) diff --git a/src/array/display.rs b/src/array/display.rs index 886f6c1bc79..ef65bb8aa95 100644 --- a/src/array/display.rs +++ b/src/array/display.rs @@ -209,14 +209,9 @@ pub fn get_value_display<'a>(array: &'a dyn Array) -> Box Strin } Union(_, _, _) => { let array = array.as_any().downcast_ref::().unwrap(); - let displays = array - .fields() - .iter() - .map(|x| get_display(x.as_ref())) - .collect::>(); Box::new(move |row: usize| { let (field, index) = array.index(row); - displays[field](index) + get_display(array.fields()[field].as_ref())(index) }) } Extension(_, _, _) => todo!(), diff --git a/src/ffi/schema.rs b/src/ffi/schema.rs index 6f53d44586d..5faf4f37188 100644 --- a/src/ffi/schema.rs +++ b/src/ffi/schema.rs @@ -380,10 +380,10 @@ fn to_format(data_type: &DataType) -> String { } DataType::Timestamp(unit, tz) => { let unit = match unit { - TimeUnit::Second => "s".to_string(), - TimeUnit::Millisecond => "m".to_string(), - TimeUnit::Microsecond => "u".to_string(), - TimeUnit::Nanosecond => "n".to_string(), + TimeUnit::Second => "s", + TimeUnit::Millisecond => "m", + TimeUnit::Microsecond => "u", + TimeUnit::Nanosecond => "n", }; format!( "ts{}:{}",