From 0e4743e7c7e4fb6336a85e05b2a231c1c3120cbd Mon Sep 17 00:00:00 2001 From: Stephen Chung Date: Thu, 19 Nov 2020 10:52:45 +0800 Subject: [PATCH] Share environment when making module from AST. --- src/ast.rs | 6 ++++++ src/module/mod.rs | 4 +--- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/src/ast.rs b/src/ast.rs index fffd0b1d..4a90262b 100644 --- a/src/ast.rs +++ b/src/ast.rs @@ -150,6 +150,12 @@ impl AST { pub(crate) fn statements_mut(&mut self) -> &mut Vec { &mut self.0 } + /// Get the internal shared `Module` containing all script-defined functions. + #[cfg(not(feature = "internals"))] + #[inline(always)] + pub(crate) fn shared_lib(&self) -> Shared { + self.1.clone() + } /// Get the internal `Module` containing all script-defined functions. #[cfg(not(feature = "internals"))] #[inline(always)] diff --git a/src/module/mod.rs b/src/module/mod.rs index 77ca74ad..f064205f 100644 --- a/src/module/mod.rs +++ b/src/module/mod.rs @@ -1521,14 +1521,12 @@ impl Module { // Non-private functions defined become module functions #[cfg(not(feature = "no_function"))] { - let ast_lib: Shared = ast.lib().clone().into(); - ast.iter_functions() .filter(|(_, access, _, _, _)| !access.is_private()) .for_each(|(_, _, _, _, func)| { // Encapsulate AST environment let mut func = func.as_ref().clone(); - func.lib = Some(ast_lib.clone()); + func.lib = Some(ast.shared_lib()); func.mods = func_mods.clone(); module.set_script_fn(func.into()); });