about summary refs log tree commit diff
path: root/compiler/rustc_data_structures/src
diff options
context:
space:
mode:
authorMark Rousskov <mark.simulacrum@gmail.com>2021-05-09 12:56:58 -0400
committerMark Rousskov <mark.simulacrum@gmail.com>2021-12-06 15:05:22 -0500
commit345ada0e1b17d21157b3963121c8238d39c763c0 (patch)
treed2bcdf026520b24e284875429c8bd2706347766a /compiler/rustc_data_structures/src
parent8991002644dc23588ca57c99d33001a13ec24061 (diff)
downloadrust-345ada0e1b17d21157b3963121c8238d39c763c0.tar.gz
rust-345ada0e1b17d21157b3963121c8238d39c763c0.zip
Optimize: reuse the real-to-preorder mapping as the visited set
Diffstat (limited to 'compiler/rustc_data_structures/src')
-rw-r--r--compiler/rustc_data_structures/src/graph/dominators/mod.rs6
1 files changed, 2 insertions, 4 deletions
diff --git a/compiler/rustc_data_structures/src/graph/dominators/mod.rs b/compiler/rustc_data_structures/src/graph/dominators/mod.rs
index 043e706c398..9d864057c85 100644
--- a/compiler/rustc_data_structures/src/graph/dominators/mod.rs
+++ b/compiler/rustc_data_structures/src/graph/dominators/mod.rs
@@ -19,11 +19,9 @@ struct PreOrderFrame<Node, Iter> {
 pub fn dominators<G: ControlFlowGraph>(graph: G) -> Dominators<G::Node> {
     // compute the post order index (rank) for each node
     let mut post_order_rank = IndexVec::from_elem_n(0, graph.num_nodes());
-    let mut visited = BitSet::new_empty(graph.num_nodes());
     let mut parent: IndexVec<usize, Option<usize>> = IndexVec::from_elem_n(None, graph.num_nodes());
 
     let mut stack = vec![PreOrderFrame { node: 0, iter: graph.successors(graph.start_node()) }];
-    visited.insert(graph.start_node());
     let mut pre_order_to_real = Vec::with_capacity(graph.num_nodes());
     let mut real_to_pre_order: IndexVec<G::Node, Option<usize>> =
         IndexVec::from_elem_n(None, graph.num_nodes());
@@ -34,10 +32,10 @@ pub fn dominators<G: ControlFlowGraph>(graph: G) -> Dominators<G::Node> {
 
     'recurse: while let Some(frame) = stack.last_mut() {
         while let Some(successor) = frame.iter.next() {
-            if visited.insert(successor) {
+            if real_to_pre_order[successor].is_none() {
+                real_to_pre_order[successor] = Some(idx);
                 parent[idx] = Some(frame.node);
                 pre_order_to_real.push(successor);
-                real_to_pre_order[successor] = Some(idx);
 
                 stack.push(PreOrderFrame { node: idx, iter: graph.successors(successor) });
                 idx += 1;