Try to get a little boost using tail call recursion
This commit is contained in:
parent
9c7ef81044
commit
7766a8ae30
|
@ -251,12 +251,16 @@ pub fn get_last_ident(exprs: &LinkedList<Expr>) -> Option<Identifier> {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn evaluate(exprs: LinkedList<Expr>, bindings: &ValueBindings) -> evaluation::Result {
|
pub fn evaluate(exprs: LinkedList<Expr>, bindings: &ValueBindings) -> evaluation::Result {
|
||||||
let bindings = bindings.nested_scope();
|
|
||||||
if exprs.iter().all(|e| !e.isnt_noop()) {
|
if exprs.iter().all(|e| !e.isnt_noop()) {
|
||||||
bindings.lookup(&exprs.back().ok_or(EvaluateError::EvaluatingZeroLengthExpr)?.identifier)
|
bindings.lookup(&exprs.back().ok_or(EvaluateError::EvaluatingZeroLengthExpr)?.identifier)
|
||||||
.ok_or_else(|| EvaluateError::UndefinedValue(exprs.back().unwrap().identifier.clone()))
|
.ok_or_else(|| EvaluateError::UndefinedValue(exprs.back().unwrap().identifier.clone()))
|
||||||
.cloned()
|
.cloned()
|
||||||
|
} else if exprs.len() == 1 {
|
||||||
|
exprs.back()
|
||||||
|
.unwrap()
|
||||||
|
.evaluate(&bindings)
|
||||||
} else {
|
} else {
|
||||||
|
let bindings = bindings.nested_scope();
|
||||||
let (all_bindings, last_ident) = exprs.into_iter()
|
let (all_bindings, last_ident) = exprs.into_iter()
|
||||||
.filter(Expr::isnt_noop)
|
.filter(Expr::isnt_noop)
|
||||||
.try_fold(
|
.try_fold(
|
||||||
|
|
Loading…
Reference in a new issue