mirror of
https://github.com/roc-lang/roc.git
synced 2025-10-01 15:51:12 +00:00
turn count_targets_help into a loop
This commit is contained in:
parent
c4e5af554b
commit
30023ac86b
1 changed files with 27 additions and 22 deletions
|
@ -1631,32 +1631,37 @@ fn count_targets(decision_tree: &Decider<u64>) -> MutMap<u64, u64> {
|
||||||
result
|
result
|
||||||
}
|
}
|
||||||
|
|
||||||
fn count_targets_help(decision_tree: &Decider<u64>, targets: &mut MutMap<u64, u64>) {
|
fn count_targets_help(initial: &Decider<u64>, targets: &mut MutMap<u64, u64>) {
|
||||||
use Decider::*;
|
use Decider::*;
|
||||||
match decision_tree {
|
|
||||||
Leaf(target) => match targets.get_mut(target) {
|
let mut stack = vec![initial];
|
||||||
None => {
|
|
||||||
targets.insert(*target, 1);
|
while let Some(decision_tree) = stack.pop() {
|
||||||
|
match decision_tree {
|
||||||
|
Leaf(target) => match targets.get_mut(target) {
|
||||||
|
None => {
|
||||||
|
targets.insert(*target, 1);
|
||||||
|
}
|
||||||
|
Some(current) => {
|
||||||
|
*current += 1;
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
Chain {
|
||||||
|
success, failure, ..
|
||||||
|
} => {
|
||||||
|
stack.push(success);
|
||||||
|
stack.push(failure);
|
||||||
}
|
}
|
||||||
Some(current) => {
|
|
||||||
*current += 1;
|
|
||||||
}
|
|
||||||
},
|
|
||||||
|
|
||||||
Chain {
|
FanOut {
|
||||||
success, failure, ..
|
tests, fallback, ..
|
||||||
} => {
|
} => {
|
||||||
count_targets_help(success, targets);
|
stack.push(fallback);
|
||||||
count_targets_help(failure, targets);
|
|
||||||
}
|
|
||||||
|
|
||||||
FanOut {
|
for (_, decider) in tests {
|
||||||
tests, fallback, ..
|
stack.push(decider);
|
||||||
} => {
|
}
|
||||||
count_targets_help(fallback, targets);
|
|
||||||
|
|
||||||
for (_, decider) in tests {
|
|
||||||
count_targets_help(decider, targets);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue