Skip to content

Commit 9e67f19

Browse files
committed
Convert some match expressions to ifs.
These make the code more concise.
1 parent 6fb1f37 commit 9e67f19

File tree

1 file changed

+21
-36
lines changed
  • src/librustc_data_structures/obligation_forest

1 file changed

+21
-36
lines changed

src/librustc_data_structures/obligation_forest/mod.rs

Lines changed: 21 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -481,12 +481,8 @@ impl<O: ForestObligation> ObligationForest<O> {
481481
// For some benchmarks this state test is extremely
482482
// hot. It's a win to handle the no-op cases immediately to avoid
483483
// the cost of the function call.
484-
match node.state.get() {
485-
// Match arms are in order of frequency. Pending, Success and
486-
// Waiting dominate; the others are rare.
487-
NodeState::Pending => {},
488-
NodeState::Success => self.find_cycles_from_node(&mut stack, processor, index),
489-
NodeState::Waiting | NodeState::Done | NodeState::Error => {},
484+
if node.state.get() == NodeState::Success {
485+
self.find_cycles_from_node(&mut stack, processor, index);
490486
}
491487
}
492488

@@ -499,34 +495,25 @@ impl<O: ForestObligation> ObligationForest<O> {
499495
where P: ObligationProcessor<Obligation=O>
500496
{
501497
let node = &self.nodes[index];
502-
match node.state.get() {
503-
NodeState::Success => {
504-
match stack.iter().rposition(|&n| n == index) {
505-
None => {
506-
stack.push(index);
507-
for &index in node.dependents.iter() {
508-
self.find_cycles_from_node(stack, processor, index);
509-
}
510-
stack.pop();
511-
node.state.set(NodeState::Done);
512-
}
513-
Some(rpos) => {
514-
// Cycle detected.
515-
processor.process_backedge(
516-
stack[rpos..].iter().map(GetObligation(&self.nodes)),
517-
PhantomData
518-
);
498+
if node.state.get() == NodeState::Success {
499+
match stack.iter().rposition(|&n| n == index) {
500+
None => {
501+
stack.push(index);
502+
for &index in node.dependents.iter() {
503+
self.find_cycles_from_node(stack, processor, index);
519504
}
505+
stack.pop();
506+
node.state.set(NodeState::Done);
507+
}
508+
Some(rpos) => {
509+
// Cycle detected.
510+
processor.process_backedge(
511+
stack[rpos..].iter().map(GetObligation(&self.nodes)),
512+
PhantomData
513+
);
520514
}
521515
}
522-
NodeState::Waiting | NodeState::Pending => {
523-
// This node is still reachable from some pending node. We
524-
// will get to it when they are all processed.
525-
}
526-
NodeState::Done | NodeState::Error => {
527-
// Already processed that node.
528-
}
529-
};
516+
}
530517
}
531518

532519
/// Returns a vector of obligations for `p` and all of its
@@ -553,12 +540,10 @@ impl<O: ForestObligation> ObligationForest<O> {
553540

554541
while let Some(index) = error_stack.pop() {
555542
let node = &self.nodes[index];
556-
match node.state.get() {
557-
NodeState::Error => continue,
558-
_ => node.state.set(NodeState::Error),
543+
if node.state.get() != NodeState::Error {
544+
node.state.set(NodeState::Error);
545+
error_stack.extend(node.dependents.iter());
559546
}
560-
561-
error_stack.extend(node.dependents.iter());
562547
}
563548

564549
trace

0 commit comments

Comments
 (0)