Change to call_fn_raw_raw.

This commit is contained in:
Stephen Chung 2022-04-23 13:28:26 +08:00
parent d61f7fa7c2
commit 0ef5c0ec54
2 changed files with 9 additions and 7 deletions

View File

@ -24,7 +24,7 @@ Enhancements
* `to_json` is added to object maps to cheaply convert it to JSON format (`()` is mapped to `null`, all other data types must be supported by JSON) * `to_json` is added to object maps to cheaply convert it to JSON format (`()` is mapped to `null`, all other data types must be supported by JSON)
* A global function `format_map_as_json` is provided which is the same as `to_json` for object maps. * A global function `format_map_as_json` is provided which is the same as `to_json` for object maps.
* `FileModuleResolver` now accepts a custom `Scope` to provide constants for optimization. * `FileModuleResolver` now accepts a custom `Scope` to provide constants for optimization.
* A new low-level method `Engine::call_fn_with_global_raw` is added to add speed to repeated function calls. * A new low-level method `Engine::call_fn_raw_raw` is added to add speed to repeated function calls.
Version 1.6.1 Version 1.6.1

View File

@ -163,6 +163,7 @@ impl Engine {
self.call_fn_internal( self.call_fn_internal(
scope, scope,
&mut GlobalRuntimeState::new(self), &mut GlobalRuntimeState::new(self),
&mut Caches::new(),
ast, ast,
eval_ast, eval_ast,
rewind_scope, rewind_scope,
@ -186,9 +187,9 @@ impl Engine {
/// ///
/// This function is very low level. /// This function is very low level.
/// ///
/// A [`GlobalRuntimeState`] needs to be passed into the function, which can be created via /// A [`GlobalRuntimeState`] and [`Caches`] need to be passed into the function, which can be
/// [`GlobalRuntimeState::new`]. This makes repeatedly calling particular functions /// created via [`GlobalRuntimeState::new`] and [`Caches::new`].
/// extremely efficient as the functions resolution cache inside the [`GlobalRuntimeState`] /// This makes repeatedly calling particular functions more efficient as the functions resolution cache
/// is kept intact. /// is kept intact.
/// ///
/// # Arguments /// # Arguments
@ -200,10 +201,11 @@ impl Engine {
/// calling this function. /// calling this function.
#[cfg(feature = "internals")] #[cfg(feature = "internals")]
#[inline(always)] #[inline(always)]
pub fn call_fn_with_global_raw( pub fn call_fn_raw_raw(
&self, &self,
scope: &mut Scope, scope: &mut Scope,
global: &mut GlobalRuntimeState, global: &mut GlobalRuntimeState,
caches: &mut Caches,
ast: &AST, ast: &AST,
eval_ast: bool, eval_ast: bool,
rewind_scope: bool, rewind_scope: bool,
@ -214,6 +216,7 @@ impl Engine {
self.call_fn_internal( self.call_fn_internal(
scope, scope,
global, global,
caches,
ast, ast,
eval_ast, eval_ast,
rewind_scope, rewind_scope,
@ -228,6 +231,7 @@ impl Engine {
&self, &self,
scope: &mut Scope, scope: &mut Scope,
global: &mut GlobalRuntimeState, global: &mut GlobalRuntimeState,
caches: &mut Caches,
ast: &AST, ast: &AST,
eval_ast: bool, eval_ast: bool,
rewind_scope: bool, rewind_scope: bool,
@ -235,8 +239,6 @@ impl Engine {
this_ptr: Option<&mut Dynamic>, this_ptr: Option<&mut Dynamic>,
arg_values: impl AsMut<[Dynamic]>, arg_values: impl AsMut<[Dynamic]>,
) -> RhaiResult { ) -> RhaiResult {
let caches = &mut Caches::new();
let statements = ast.statements(); let statements = ast.statements();
let orig_scope_len = scope.len(); let orig_scope_len = scope.len();