Skip to content

Commit aaff05b

Browse files
committed
Reorder the state handling in process_cycles().
This gives a slight speed-up.
1 parent 9b9d2af commit aaff05b

File tree

1 file changed

+9
-6
lines changed
  • src/librustc_data_structures/obligation_forest

1 file changed

+9
-6
lines changed

src/librustc_data_structures/obligation_forest/mod.rs

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -484,13 +484,16 @@ impl<O: ForestObligation> ObligationForest<O> {
484484
debug!("process_cycles()");
485485

486486
for (index, node) in self.nodes.iter().enumerate() {
487-
// For rustc-benchmarks/inflate-0.1.0 this state test is extremely
488-
// hot and the state is almost always `Pending` or `Waiting`. It's
489-
// a win to handle the no-op cases immediately to avoid the cost of
490-
// the function call.
487+
// For some benchmarks this state test is extremely
488+
// hot. It's a win to handle the no-op cases immediately to avoid
489+
// the cost of the function call.
491490
match node.state.get() {
492-
NodeState::Waiting | NodeState::Pending | NodeState::Done | NodeState::Error => {},
493-
_ => self.find_cycles_from_node(&mut stack, processor, index),
491+
// Match arms are in order of frequency. Pending, Success and
492+
// Waiting dominate; the others are rare.
493+
NodeState::Pending => {},
494+
NodeState::Success => self.find_cycles_from_node(&mut stack, processor, index),
495+
NodeState::Waiting | NodeState::Done | NodeState::Error => {},
496+
NodeState::OnDfsStack => self.find_cycles_from_node(&mut stack, processor, index),
494497
}
495498
}
496499

0 commit comments

Comments
 (0)