perf: reduce one hashmap lookup
This commit is contained in:
parent
0f4df9c4e7
commit
ab23094d65
@ -258,31 +258,39 @@ impl Engine {
|
|||||||
|
|
||||||
let cache = caches.fn_resolution_cache_mut();
|
let cache = caches.fn_resolution_cache_mut();
|
||||||
|
|
||||||
let func = if let Entry::Vacant(entry) = cache.entry(hash) {
|
let func = match cache.entry(hash) {
|
||||||
let func = if args.len() == 2 {
|
Entry::Vacant(entry) => {
|
||||||
get_builtin_binary_op_fn(&name, operands[0], operands[1])
|
let func = if args.len() == 2 {
|
||||||
} else {
|
get_builtin_binary_op_fn(&name, operands[0], operands[1])
|
||||||
None
|
} else {
|
||||||
};
|
None
|
||||||
|
};
|
||||||
|
|
||||||
if let Some(f) = func {
|
if let Some(f) = func {
|
||||||
entry.insert(Some(FnResolutionCacheEntry {
|
&entry
|
||||||
func: CallableFunction::from_method(Box::new(f) as Box<FnAny>),
|
.insert(Some(FnResolutionCacheEntry {
|
||||||
source: None,
|
func: CallableFunction::from_method(Box::new(f) as Box<FnAny>),
|
||||||
}));
|
source: None,
|
||||||
&cache.get(&hash).unwrap().as_ref().unwrap().func
|
}))
|
||||||
} else {
|
.as_ref()
|
||||||
let result = self.exec_fn_call(
|
.unwrap()
|
||||||
None, global, caches, lib, name, *hashes, operands, false, false, pos,
|
.func
|
||||||
level,
|
} else {
|
||||||
);
|
let result = self.exec_fn_call(
|
||||||
return result.map(|(v, ..)| v);
|
None, global, caches, lib, name, *hashes, operands, false, false, pos,
|
||||||
|
level,
|
||||||
|
);
|
||||||
|
return result.map(|(v, ..)| v);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Entry::Occupied(entry) => {
|
||||||
|
if let Some(entry) = entry.into_mut() {
|
||||||
|
&entry.func
|
||||||
|
} else {
|
||||||
|
let sig = gen_fn_call_signature(self, name, operands);
|
||||||
|
return Err(ERR::ErrorFunctionNotFound(sig, pos).into());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
} else if let Some(entry) = cache.get(&hash).unwrap() {
|
|
||||||
&entry.func
|
|
||||||
} else {
|
|
||||||
let sig = gen_fn_call_signature(self, name, operands);
|
|
||||||
return Err(ERR::ErrorFunctionNotFound(sig, pos).into());
|
|
||||||
};
|
};
|
||||||
|
|
||||||
let context = (self, name, None, &*global, lib, pos, level).into();
|
let context = (self, name, None, &*global, lib, pos, level).into();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user