Avoid unnecessarily creating Scope.
This commit is contained in:
@@ -202,7 +202,11 @@ impl Engine {
|
||||
scope: &Scope,
|
||||
scripts: impl AsRef<[S]>,
|
||||
) -> ParseResult<AST> {
|
||||
self.compile_with_scope_and_optimization_level(scope, scripts, self.optimization_level)
|
||||
self.compile_with_scope_and_optimization_level(
|
||||
Some(scope),
|
||||
scripts,
|
||||
self.optimization_level,
|
||||
)
|
||||
}
|
||||
/// Join a list of strings and compile into an [`AST`] using own scope at a specific optimization level.
|
||||
///
|
||||
@@ -214,7 +218,7 @@ impl Engine {
|
||||
#[inline]
|
||||
pub(crate) fn compile_with_scope_and_optimization_level<S: AsRef<str>>(
|
||||
&self,
|
||||
scope: &Scope,
|
||||
scope: Option<&Scope>,
|
||||
scripts: impl AsRef<[S]>,
|
||||
optimization_level: OptimizationLevel,
|
||||
) -> ParseResult<AST> {
|
||||
@@ -291,7 +295,7 @@ impl Engine {
|
||||
let scripts = [script];
|
||||
let (stream, t) = self.lex_raw(&scripts, self.token_mapper.as_deref());
|
||||
let interned_strings = &mut *locked_write(&self.interned_strings);
|
||||
let state = &mut ParseState::new(scope, interned_strings, t);
|
||||
let state = &mut ParseState::new(Some(scope), interned_strings, t);
|
||||
self.parse_global_expr(stream.peekable(), state, |_| {}, self.optimization_level)
|
||||
}
|
||||
}
|
||||
|
@@ -69,7 +69,7 @@ impl Engine {
|
||||
script: &str,
|
||||
) -> RhaiResultOf<T> {
|
||||
let ast = self.compile_with_scope_and_optimization_level(
|
||||
scope,
|
||||
Some(scope),
|
||||
[script],
|
||||
self.optimization_level,
|
||||
)?;
|
||||
@@ -123,7 +123,7 @@ impl Engine {
|
||||
|
||||
let (stream, tc) = self.lex_raw(&scripts, self.token_mapper.as_deref());
|
||||
|
||||
let state = &mut ParseState::new(scope, interned_strings, tc);
|
||||
let state = &mut ParseState::new(Some(scope), interned_strings, tc);
|
||||
|
||||
// No need to optimize a lone expression
|
||||
self.parse_global_expr(
|
||||
|
@@ -4,7 +4,7 @@ use crate::parser::{ParseResult, ParseState};
|
||||
use crate::types::StringsInterner;
|
||||
use crate::{
|
||||
Engine, ExclusiveRange, FnPtr, ImmutableString, InclusiveRange, OptimizationLevel, Position,
|
||||
RhaiError, Scope, SmartString, ERR,
|
||||
RhaiError, SmartString, ERR,
|
||||
};
|
||||
use std::any::type_name;
|
||||
#[cfg(feature = "no_std")]
|
||||
@@ -282,9 +282,8 @@ impl Engine {
|
||||
let (mut stream, tc) = self.lex_raw(&scripts, self.token_mapper.as_deref());
|
||||
tc.borrow_mut().compressed = Some(String::new());
|
||||
stream.state.last_token = Some(SmartString::new_const());
|
||||
let scope = Scope::new();
|
||||
let mut interner = StringsInterner::new();
|
||||
let mut state = ParseState::new(&scope, &mut interner, tc);
|
||||
let mut state = ParseState::new(None, &mut interner, tc);
|
||||
let mut _ast = self.parse(
|
||||
stream.peekable(),
|
||||
&mut state,
|
||||
|
@@ -4,7 +4,7 @@
|
||||
use crate::func::native::locked_write;
|
||||
use crate::parser::{ParseSettingFlags, ParseState};
|
||||
use crate::tokenizer::Token;
|
||||
use crate::{Engine, LexError, Map, OptimizationLevel, RhaiResultOf, Scope};
|
||||
use crate::{Engine, LexError, Map, OptimizationLevel, RhaiResultOf};
|
||||
#[cfg(feature = "no_std")]
|
||||
use std::prelude::v1::*;
|
||||
|
||||
@@ -115,9 +115,8 @@ impl Engine {
|
||||
);
|
||||
|
||||
let ast = {
|
||||
let scope = Scope::new();
|
||||
let interned_strings = &mut *locked_write(&self.interned_strings);
|
||||
let state = &mut ParseState::new(&scope, interned_strings, tokenizer_control);
|
||||
let state = &mut ParseState::new(None, interned_strings, tokenizer_control);
|
||||
|
||||
self.parse_global_expr(
|
||||
stream.peekable(),
|
||||
|
@@ -52,7 +52,7 @@ impl Engine {
|
||||
let mut ast = ast;
|
||||
|
||||
let mut _new_ast = self.optimize_into_ast(
|
||||
scope,
|
||||
Some(scope),
|
||||
ast.take_statements(),
|
||||
#[cfg(not(feature = "no_function"))]
|
||||
ast.shared_lib()
|
||||
|
@@ -60,7 +60,7 @@ impl Engine {
|
||||
let ast = {
|
||||
let (stream, tc) = self.lex_raw(&scripts, self.token_mapper.as_deref());
|
||||
let interned_strings = &mut *locked_write(&self.interned_strings);
|
||||
let state = &mut ParseState::new(scope, interned_strings, tc);
|
||||
let state = &mut ParseState::new(Some(scope), interned_strings, tc);
|
||||
self.parse(stream.peekable(), state, self.optimization_level)?
|
||||
};
|
||||
self.run_ast_with_scope(scope, &ast)
|
||||
|
Reference in New Issue
Block a user