Skip to content

Commit

Permalink
perf: preallocate capacity with an upperbound
Browse files Browse the repository at this point in the history
  • Loading branch information
jpedroh committed Jul 23, 2024
1 parent 6a4606c commit 52fa6d1
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 3 deletions.
3 changes: 2 additions & 1 deletion merge/src/ordered_merge.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ pub fn ordered_merge<'a>(
));
}

let mut result_children = vec![];
let mut result_children =
Vec::with_capacity(left.get_children().len() + right.get_children().len());

let mut children_left_it = left.get_children().iter();
let mut children_right_it = right.get_children().iter();
Expand Down
5 changes: 3 additions & 2 deletions merge/src/unordered_merge.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,9 @@ pub fn unordered_merge<'a>(
));
}

let mut result_children = vec![];
let mut processed_nodes: HashSet<uuid::Uuid> = HashSet::new();
let max_capacity = left.get_children().len() + right.get_children().len();
let mut result_children = Vec::with_capacity(max_capacity);
let mut processed_nodes = HashSet::with_capacity(max_capacity);

for left_child in left.get_children().iter() {
if let CSTNode::Terminal(Terminal {
Expand Down

0 comments on commit 52fa6d1

Please sign in to comment.