Try to get a little boost using tail call recursion

This commit is contained in:
Emi Simpson 2022-04-25 10:10:37 -04:00
parent 9c7ef81044
commit 7766a8ae30
Signed by: Emi
GPG Key ID: A12F2C2FFDC3D847
1 changed files with 5 additions and 1 deletions

View File

@ -251,12 +251,16 @@ pub fn get_last_ident(exprs: &LinkedList<Expr>) -> Option<Identifier> {
}
pub fn evaluate(exprs: LinkedList<Expr>, bindings: &ValueBindings) -> evaluation::Result {
let bindings = bindings.nested_scope();
if exprs.iter().all(|e| !e.isnt_noop()) {
bindings.lookup(&exprs.back().ok_or(EvaluateError::EvaluatingZeroLengthExpr)?.identifier)
.ok_or_else(|| EvaluateError::UndefinedValue(exprs.back().unwrap().identifier.clone()))
.cloned()
} else if exprs.len() == 1 {
exprs.back()
.unwrap()
.evaluate(&bindings)
} else {
let bindings = bindings.nested_scope();
let (all_bindings, last_ident) = exprs.into_iter()
.filter(Expr::isnt_noop)
.try_fold(