Skip to content

Commit

Permalink
Pre-allocate sorted key vectors to reduce allocations.
Browse files Browse the repository at this point in the history
Intended to improve performance, but realistically I haven't measured
much of a difference.
  • Loading branch information
david-cattermole committed Feb 13, 2024
1 parent 2c1fef1 commit aa7741f
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions print-lib/src/aggregate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ pub fn sum_entry_activity_duration(
pub fn get_map_keys_sorted_general<KeyType: Clone + Ord, ValueType: Clone>(
map_keys: &Keys<KeyType, ValueType>,
) -> Vec<KeyType> {
let mut sorted_keys = Vec::new();
let mut sorted_keys = Vec::with_capacity(map_keys.len());
for key in map_keys.clone() {
sorted_keys.push(key.clone());
}
Expand All @@ -193,7 +193,7 @@ pub fn get_map_keys_sorted_general<KeyType: Clone + Ord, ValueType: Clone>(
}

pub fn get_map_keys_sorted_strings<T>(map_keys: &Keys<String, T>) -> Vec<String> {
let mut sorted_keys = Vec::new();
let mut sorted_keys = Vec::with_capacity(map_keys.len());
for key in map_keys.clone() {
// Ignores 'unknown' tasks; tasks without a valid value.
if !key.is_empty() {
Expand Down

0 comments on commit aa7741f

Please sign in to comment.