perf: reduce one hashmap lookup
This commit is contained in:
parent
0f4df9c4e7
commit
ab23094d65
@ -258,7 +258,8 @@ 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) {
|
||||||
|
Entry::Vacant(entry) => {
|
||||||
let func = if args.len() == 2 {
|
let func = if args.len() == 2 {
|
||||||
get_builtin_binary_op_fn(&name, operands[0], operands[1])
|
get_builtin_binary_op_fn(&name, operands[0], operands[1])
|
||||||
} else {
|
} else {
|
||||||
@ -266,11 +267,14 @@ impl Engine {
|
|||||||
};
|
};
|
||||||
|
|
||||||
if let Some(f) = func {
|
if let Some(f) = func {
|
||||||
entry.insert(Some(FnResolutionCacheEntry {
|
&entry
|
||||||
|
.insert(Some(FnResolutionCacheEntry {
|
||||||
func: CallableFunction::from_method(Box::new(f) as Box<FnAny>),
|
func: CallableFunction::from_method(Box::new(f) as Box<FnAny>),
|
||||||
source: None,
|
source: None,
|
||||||
}));
|
}))
|
||||||
&cache.get(&hash).unwrap().as_ref().unwrap().func
|
.as_ref()
|
||||||
|
.unwrap()
|
||||||
|
.func
|
||||||
} else {
|
} else {
|
||||||
let result = self.exec_fn_call(
|
let result = self.exec_fn_call(
|
||||||
None, global, caches, lib, name, *hashes, operands, false, false, pos,
|
None, global, caches, lib, name, *hashes, operands, false, false, pos,
|
||||||
@ -278,11 +282,15 @@ impl Engine {
|
|||||||
);
|
);
|
||||||
return result.map(|(v, ..)| v);
|
return result.map(|(v, ..)| v);
|
||||||
}
|
}
|
||||||
} else if let Some(entry) = cache.get(&hash).unwrap() {
|
}
|
||||||
|
Entry::Occupied(entry) => {
|
||||||
|
if let Some(entry) = entry.into_mut() {
|
||||||
&entry.func
|
&entry.func
|
||||||
} else {
|
} else {
|
||||||
let sig = gen_fn_call_signature(self, name, operands);
|
let sig = gen_fn_call_signature(self, name, operands);
|
||||||
return Err(ERR::ErrorFunctionNotFound(sig, pos).into());
|
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