From 7766a8ae3048e5147bfbbe1195c05cc63aecf86e Mon Sep 17 00:00:00 2001 From: Emi Simpson Date: Mon, 25 Apr 2022 10:10:37 -0400 Subject: [PATCH] Try to get a little boost using tail call recursion --- src/ir/expr.rs | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/ir/expr.rs b/src/ir/expr.rs index 8a9f531..bab0d9e 100644 --- a/src/ir/expr.rs +++ b/src/ir/expr.rs @@ -251,12 +251,16 @@ pub fn get_last_ident(exprs: &LinkedList) -> Option { } pub fn evaluate(exprs: LinkedList, 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(