Remove duplicated functions lookup for script function call.

This commit is contained in:
Stephen Chung 2021-02-11 12:13:30 +08:00
parent 645e1fe583
commit d49581356d

View File

@ -577,7 +577,7 @@ impl Engine {
// Qualifiers (none) + function name + number of arguments + argument `TypeId`'s.
let arg_types = args.iter().map(|a| a.type_id());
let hash_fn = calc_native_fn_hash(empty(), fn_name, arg_types);
let hash_fn = calc_native_fn_hash(empty(), fn_name, arg_types).unwrap();
match fn_name {
// type_of
@ -587,7 +587,7 @@ impl Engine {
Some(mods),
Some(state),
lib,
hash_fn,
Some(hash_fn),
hash_script,
pub_only,
) =>
@ -606,7 +606,7 @@ impl Engine {
Some(mods),
Some(state),
lib,
hash_fn,
Some(hash_fn),
hash_script,
pub_only,
) =>
@ -622,14 +622,11 @@ impl Engine {
.into()
}
// Script-like function found
#[cfg(not(feature = "no_function"))]
_ if hash_script.is_some()
&& self.has_override(Some(mods), Some(state), lib, None, hash_script, pub_only) =>
{
_ if hash_script.is_some() => {
let hash_script = hash_script.unwrap();
// Check if function access already in the cache
// Check if script function access already in the cache
let (func, source) = state
.fn_resolution_cache_mut()
.entry(hash_script)
@ -649,9 +646,11 @@ impl Engine {
//.or_else(|| mods.iter().find_map(|(_, m)| m.get_qualified_fn(hash_script).map(|f| (f, m.id_raw().clone()))))
})
.as_ref()
.map(|(f, s)| (f.clone(), s.clone()))
.unwrap();
.map(|(f, s)| (Some(f.clone()), s.clone()))
.unwrap_or((None, None));
if let Some(func) = func {
// Script function call
assert!(func.is_script());
let func = func.get_fn_def();
@ -708,8 +707,9 @@ impl Engine {
let level = _level + 1;
let result = self
.call_script_fn(scope, mods, state, lib, &mut None, func, args, pos, level);
let result = self.call_script_fn(
scope, mods, state, lib, &mut None, func, args, pos, level,
);
// Restore the original source
state.source = orig_source;
@ -721,20 +721,17 @@ impl Engine {
};
Ok((result, false))
} else {
// Native function call
self.call_native_fn(
mods, state, lib, fn_name, hash_fn, args, is_ref, pub_only, pos, def_val,
)
}
}
// Normal native function call
// Native function call
_ => self.call_native_fn(
mods,
state,
lib,
fn_name,
hash_fn.unwrap(),
args,
is_ref,
pub_only,
pos,
def_val,
mods, state, lib, fn_name, hash_fn, args, is_ref, pub_only, pos, def_val,
),
}
}