mirror of
https://github.com/roc-lang/roc.git
synced 2025-10-01 07:41: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,8 +1631,12 @@ fn count_targets(decision_tree: &Decider<u64>) -> MutMap<u64, u64> {
|
|||
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::*;
|
||||
|
||||
let mut stack = vec![initial];
|
||||
|
||||
while let Some(decision_tree) = stack.pop() {
|
||||
match decision_tree {
|
||||
Leaf(target) => match targets.get_mut(target) {
|
||||
None => {
|
||||
|
@ -1646,17 +1650,18 @@ fn count_targets_help(decision_tree: &Decider<u64>, targets: &mut MutMap<u64, u6
|
|||
Chain {
|
||||
success, failure, ..
|
||||
} => {
|
||||
count_targets_help(success, targets);
|
||||
count_targets_help(failure, targets);
|
||||
stack.push(success);
|
||||
stack.push(failure);
|
||||
}
|
||||
|
||||
FanOut {
|
||||
tests, fallback, ..
|
||||
} => {
|
||||
count_targets_help(fallback, targets);
|
||||
stack.push(fallback);
|
||||
|
||||
for (_, decider) in tests {
|
||||
count_targets_help(decider, targets);
|
||||
stack.push(decider);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue