Skip to content
This repository has been archived by the owner on Feb 18, 2024. It is now read-only.

Commit

Permalink
Avoid unnecessary allocations (#559)
Browse files Browse the repository at this point in the history
* Avoid unnecessary to_string allocations

* Only get displayer for the interesting field
  • Loading branch information
simonvandel authored Oct 30, 2021
1 parent cdcf150 commit 31d57b8
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 10 deletions.
7 changes: 1 addition & 6 deletions src/array/display.rs
Original file line number Diff line number Diff line change
Expand Up @@ -209,14 +209,9 @@ pub fn get_value_display<'a>(array: &'a dyn Array) -> Box<dyn Fn(usize) -> Strin
}
Union(_, _, _) => {
let array = array.as_any().downcast_ref::<UnionArray>().unwrap();
let displays = array
.fields()
.iter()
.map(|x| get_display(x.as_ref()))
.collect::<Vec<_>>();
Box::new(move |row: usize| {
let (field, index) = array.index(row);
displays[field](index)
get_display(array.fields()[field].as_ref())(index)
})
}
Extension(_, _, _) => todo!(),
Expand Down
8 changes: 4 additions & 4 deletions src/ffi/schema.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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{}:{}",
Expand Down

0 comments on commit 31d57b8

Please sign in to comment.