diff --git a/merge/src/ordered_merge.rs b/merge/src/ordered_merge.rs index e9d71c8..a422fc9 100644 --- a/merge/src/ordered_merge.rs +++ b/merge/src/ordered_merge.rs @@ -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(); diff --git a/merge/src/unordered_merge.rs b/merge/src/unordered_merge.rs index 07a3fc5..e675612 100644 --- a/merge/src/unordered_merge.rs +++ b/merge/src/unordered_merge.rs @@ -23,8 +23,9 @@ pub fn unordered_merge<'a>( )); } - let mut result_children = vec![]; - let mut processed_nodes: HashSet = 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 {