mirror of
https://github.com/roc-lang/roc.git
synced 2025-09-30 15:21:12 +00:00
refactor
This commit is contained in:
parent
b2792af5f6
commit
b99f710c49
1 changed files with 15 additions and 9 deletions
|
@ -155,19 +155,25 @@ fn to_decision_tree(raw_branches: Vec<Branch>) -> DecisionTree {
|
||||||
.map(|(a, b)| (a, to_decision_tree(b)))
|
.map(|(a, b)| (a, to_decision_tree(b)))
|
||||||
.collect();
|
.collect();
|
||||||
|
|
||||||
match (decision_edges.split_last_mut(), fallback.split_last()) {
|
match (decision_edges.as_slice(), fallback.as_slice()) {
|
||||||
(Some(((_tag, decision_tree), rest)), None) if rest.is_empty() => {
|
([(_test, _decision_tree)], []) => {
|
||||||
// TODO remove clone
|
// only one test with no fallback: we will always enter this branch
|
||||||
decision_tree.clone()
|
|
||||||
|
// get the `_decision_tree` without cloning
|
||||||
|
decision_edges.pop().unwrap().1
|
||||||
}
|
}
|
||||||
(_, None) => DecisionTree::Decision {
|
(_, []) => DecisionTree::Decision {
|
||||||
path: path.clone(),
|
path,
|
||||||
edges: decision_edges,
|
edges: decision_edges,
|
||||||
default: None,
|
default: None,
|
||||||
},
|
},
|
||||||
(None, Some(_)) => to_decision_tree(fallback),
|
([], _) => {
|
||||||
_ => DecisionTree::Decision {
|
// should be guaranteed by the patterns
|
||||||
path: path.clone(),
|
debug_assert!(!fallback.is_empty());
|
||||||
|
to_decision_tree(fallback)
|
||||||
|
}
|
||||||
|
(_, _) => DecisionTree::Decision {
|
||||||
|
path,
|
||||||
edges: decision_edges,
|
edges: decision_edges,
|
||||||
default: Some(Box::new(to_decision_tree(fallback))),
|
default: Some(Box::new(to_decision_tree(fallback))),
|
||||||
},
|
},
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue