From dff124b2428e136ca29026225aaacefc9e4448b2 Mon Sep 17 00:00:00 2001 From: Stephen Chung Date: Sat, 6 Feb 2021 22:16:05 +0800 Subject: [PATCH] Save functions resolution cache during script call. --- src/fn_call.rs | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/fn_call.rs b/src/fn_call.rs index 03d9e33a..e309a8db 100644 --- a/src/fn_call.rs +++ b/src/fn_call.rs @@ -392,10 +392,10 @@ impl Engine { // Merge in encapsulated environment, if any let mut lib_merged: StaticVec<_>; + let mut old_cache = None; let unified_lib = if let Some(ref env_lib) = fn_def.lib { - // If the library is modified, clear the functions lookup cache - state.functions_cache.clear(); + old_cache = Some(mem::take(&mut state.functions_cache)); lib_merged = Default::default(); lib_merged.push(env_lib.as_ref()); @@ -467,6 +467,10 @@ impl Engine { mods.truncate(prev_mods_len); state.scope_level = orig_scope_level; + if let Some(cache) = old_cache { + state.functions_cache = cache; + } + result }