Convert some match expressions to ifs.

These make the code more concise.
This commit is contained in:
Nicholas Nethercote 2019-09-25 12:03:31 +10:00
parent 6fb1f37888
commit 9e67f19eee

View File

@ -481,12 +481,8 @@ impl<O: ForestObligation> ObligationForest<O> {
// For some benchmarks this state test is extremely
// hot. It's a win to handle the no-op cases immediately to avoid
// the cost of the function call.
match node.state.get() {
// Match arms are in order of frequency. Pending, Success and
// Waiting dominate; the others are rare.
NodeState::Pending => {},
NodeState::Success => self.find_cycles_from_node(&mut stack, processor, index),
NodeState::Waiting | NodeState::Done | NodeState::Error => {},
if node.state.get() == NodeState::Success {
self.find_cycles_from_node(&mut stack, processor, index);
}
}
@ -499,8 +495,7 @@ impl<O: ForestObligation> ObligationForest<O> {
where P: ObligationProcessor<Obligation=O>
{
let node = &self.nodes[index];
match node.state.get() {
NodeState::Success => {
if node.state.get() == NodeState::Success {
match stack.iter().rposition(|&n| n == index) {
None => {
stack.push(index);
@ -519,14 +514,6 @@ impl<O: ForestObligation> ObligationForest<O> {
}
}
}
NodeState::Waiting | NodeState::Pending => {
// This node is still reachable from some pending node. We
// will get to it when they are all processed.
}
NodeState::Done | NodeState::Error => {
// Already processed that node.
}
};
}
/// Returns a vector of obligations for `p` and all of its
@ -553,13 +540,11 @@ impl<O: ForestObligation> ObligationForest<O> {
while let Some(index) = error_stack.pop() {
let node = &self.nodes[index];
match node.state.get() {
NodeState::Error => continue,
_ => node.state.set(NodeState::Error),
}
if node.state.get() != NodeState::Error {
node.state.set(NodeState::Error);
error_stack.extend(node.dependents.iter());
}
}
trace
}