mirror of
https://github.com/rust-lang/rust.git
synced 2024-11-22 23:04:33 +00:00
Optimization: process buckets only once
This commit is contained in:
parent
c82fe0efb4
commit
7379d24ebc
@ -72,6 +72,14 @@ fn dominators_given_rpo<G: ControlFlowGraph>(graph: G, rpo: &[G::Node]) -> Domin
|
|||||||
let mut lastlinked = None;
|
let mut lastlinked = None;
|
||||||
|
|
||||||
for &w in pre_order_nodes[1..].iter().rev() {
|
for &w in pre_order_nodes[1..].iter().rev() {
|
||||||
|
// Optimization: process buckets just once. We need not explicitly empty
|
||||||
|
// the bucket here, but mem::take is pretty cheap.
|
||||||
|
let z = parent[w].unwrap();
|
||||||
|
for v in std::mem::take(&mut bucket[z]) {
|
||||||
|
let y = eval(&pre_order_index, &mut parent, lastlinked, &semi, &mut label, v);
|
||||||
|
idom[v] = if pre_order_index[semi[y]] < pre_order_index[z] { y } else { z };
|
||||||
|
}
|
||||||
|
|
||||||
semi[w] = w;
|
semi[w] = w;
|
||||||
for v in graph.predecessors(w) {
|
for v in graph.predecessors(w) {
|
||||||
let x = eval(&pre_order_index, &mut parent, lastlinked, &semi, &mut label, v);
|
let x = eval(&pre_order_index, &mut parent, lastlinked, &semi, &mut label, v);
|
||||||
@ -85,13 +93,6 @@ fn dominators_given_rpo<G: ControlFlowGraph>(graph: G, rpo: &[G::Node]) -> Domin
|
|||||||
|
|
||||||
bucket[semi[w]].push(w);
|
bucket[semi[w]].push(w);
|
||||||
|
|
||||||
link(&mut ancestor, &parent, w);
|
|
||||||
let z = parent[w].unwrap();
|
|
||||||
for v in std::mem::take(&mut bucket[z]) {
|
|
||||||
let y = eval(&pre_order_index, &mut ancestor, &semi, &mut label, v);
|
|
||||||
idom[v] = if pre_order_index[semi[y]] < pre_order_index[z] { y } else { z };
|
|
||||||
}
|
|
||||||
|
|
||||||
// Optimization: We share the parent array between processed and not
|
// Optimization: We share the parent array between processed and not
|
||||||
// processed elements; lastlinked represents the divider.
|
// processed elements; lastlinked represents the divider.
|
||||||
lastlinked = Some(w);
|
lastlinked = Some(w);
|
||||||
|
Loading…
Reference in New Issue
Block a user