From 9c6d6dc9aa1ebc55338e2a834034c6e63e48661c Mon Sep 17 00:00:00 2001 From: Johan Milanov Date: Mon, 3 Apr 2023 22:49:36 +0200 Subject: [PATCH] Slightly more efficient vec initialization (#120) This will, at least on x86_64, compile down to simpler, shorter assembly that uses a zeroed allocation instead of a regular allocation, a memset and various `raw_vec` methods. --- src/postorder.rs | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/postorder.rs b/src/postorder.rs index 3e04eb0..020e4ea 100644 --- a/src/postorder.rs +++ b/src/postorder.rs @@ -18,8 +18,7 @@ pub fn calculate<'a, SuccFn: Fn(Block) -> &'a [Block]>( let mut ret = vec![]; // State: visited-block map, and explicit DFS stack. - let mut visited = vec![]; - visited.resize(num_blocks, false); + let mut visited = vec![false; num_blocks]; struct State<'a> { block: Block,