Optimize Scope.

This commit is contained in:
Stephen Chung
2020-11-01 22:46:46 +08:00
parent 3485f9b00b
commit c55fc5a9a5
5 changed files with 109 additions and 146 deletions

View File

@@ -16,7 +16,7 @@ use crate::{ast::ScriptFnDef, fn_native::Shared};
use crate::{
ast::AST,
engine::{Engine, Imports},
scope::{Entry as ScopeEntry, Scope},
scope::Scope,
};
#[cfg(not(feature = "no_index"))]
@@ -1348,14 +1348,12 @@ impl Module {
// Create new module
let mut module = Module::new();
scope
.into_iter()
.for_each(|ScopeEntry { value, alias, .. }| {
// Variables with an alias left in the scope become module variables
if let Some(alias) = alias {
module.variables.insert(*alias, value);
}
});
scope.into_iter().for_each(|(_, _, value, alias)| {
// Variables with an alias left in the scope become module variables
if let Some(alias) = alias {
module.variables.insert(alias, value);
}
});
// Modules left in the scope become sub-modules
mods.into_iter().for_each(|(alias, m)| {