From 81894e52cb4efff9037f19ca9600fa83ca975be9 Mon Sep 17 00:00:00 2001 From: Stephen Chung Date: Fri, 10 Apr 2020 21:02:38 +0800 Subject: [PATCH] Do not optimize single-use AST's. --- src/api.rs | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/src/api.rs b/src/api.rs index 9b25a7cc..fde9b5d4 100644 --- a/src/api.rs +++ b/src/api.rs @@ -689,7 +689,9 @@ impl<'e> Engine<'e> { scope: &mut Scope, script: &str, ) -> Result { - let ast = self.compile(script)?; + // Since the AST will be thrown away afterwards, don't bother to optimize it + let ast = + self.compile_with_scope_and_optimization_level(scope, script, OptimizationLevel::None)?; self.eval_ast_with_scope(scope, &ast) } @@ -734,8 +736,10 @@ impl<'e> Engine<'e> { scope: &mut Scope, script: &str, ) -> Result { - let ast = self.compile_expression(script)?; - + let scripts = [script]; + let stream = lex(&scripts); + // Since the AST will be thrown away afterwards, don't bother to optimize it + let ast = parse_global_expr(&mut stream.peekable(), self, scope, OptimizationLevel::None)?; self.eval_ast_with_scope(scope, &ast) } @@ -850,7 +854,9 @@ impl<'e> Engine<'e> { pub fn consume_with_scope(&self, scope: &mut Scope, script: &str) -> Result<(), EvalAltResult> { let scripts = [script]; let stream = lex(&scripts); - let ast = parse(&mut stream.peekable(), self, scope, self.optimization_level)?; + + // Since the AST will be thrown away afterwards, don't bother to optimize it + let ast = parse(&mut stream.peekable(), self, scope, OptimizationLevel::None)?; self.consume_ast_with_scope(scope, &ast) }