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
|
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::*;
|
||||||
|
|
||||||
|
let mut stack = vec![initial];
|
||||||
|
|
||||||
|
while let Some(decision_tree) = stack.pop() {
|
||||||
match decision_tree {
|
match decision_tree {
|
||||||
Leaf(target) => match targets.get_mut(target) {
|
Leaf(target) => match targets.get_mut(target) {
|
||||||
None => {
|
None => {
|
||||||
|
@ -1646,17 +1650,18 @@ fn count_targets_help(decision_tree: &Decider<u64>, targets: &mut MutMap<u64, u6
|
||||||
Chain {
|
Chain {
|
||||||
success, failure, ..
|
success, failure, ..
|
||||||
} => {
|
} => {
|
||||||
count_targets_help(success, targets);
|
stack.push(success);
|
||||||
count_targets_help(failure, targets);
|
stack.push(failure);
|
||||||
}
|
}
|
||||||
|
|
||||||
FanOut {
|
FanOut {
|
||||||
tests, fallback, ..
|
tests, fallback, ..
|
||||||
} => {
|
} => {
|
||||||
count_targets_help(fallback, targets);
|
stack.push(fallback);
|
||||||
|
|
||||||
for (_, decider) in tests {
|
for (_, decider) in tests {
|
||||||
count_targets_help(decider, targets);
|
stack.push(decider);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue