Use tokens to speed up function name lookup.
This commit is contained in:
@@ -50,7 +50,7 @@ impl Engine {
|
||||
idx_values: &mut FnArgsVec<Dynamic>,
|
||||
chain_type: ChainType,
|
||||
level: usize,
|
||||
new_val: Option<(Dynamic, OpAssignment)>,
|
||||
new_val: Option<(Dynamic, &OpAssignment)>,
|
||||
) -> RhaiResultOf<(Dynamic, bool)> {
|
||||
let is_ref_mut = target.is_ref();
|
||||
|
||||
@@ -558,7 +558,7 @@ impl Engine {
|
||||
this_ptr: &mut Option<&mut Dynamic>,
|
||||
expr: &Expr,
|
||||
level: usize,
|
||||
new_val: Option<(Dynamic, OpAssignment)>,
|
||||
new_val: Option<(Dynamic, &OpAssignment)>,
|
||||
) -> RhaiResult {
|
||||
let chain_type = ChainType::from(expr);
|
||||
let (crate::ast::BinaryExpr { lhs, rhs }, options, op_pos) = match expr {
|
||||
|
@@ -219,11 +219,15 @@ impl Engine {
|
||||
level: usize,
|
||||
) -> RhaiResult {
|
||||
let FnCallExpr {
|
||||
name, hashes, args, ..
|
||||
name,
|
||||
hashes,
|
||||
args,
|
||||
operator_token,
|
||||
..
|
||||
} = expr;
|
||||
|
||||
// Short-circuit native binary operator call if under Fast Operators mode
|
||||
if expr.is_native_operator && self.fast_operators() && args.len() == 2 {
|
||||
if operator_token.is_some() && self.fast_operators() && args.len() == 2 {
|
||||
let mut lhs = self
|
||||
.get_arg_value(scope, global, caches, lib, this_ptr, &args[0], level)?
|
||||
.0
|
||||
@@ -236,7 +240,9 @@ impl Engine {
|
||||
|
||||
let operands = &mut [&mut lhs, &mut rhs];
|
||||
|
||||
if let Some(func) = get_builtin_binary_op_fn(name, operands[0], operands[1]) {
|
||||
if let Some(func) =
|
||||
get_builtin_binary_op_fn(operator_token.as_ref().unwrap(), operands[0], operands[1])
|
||||
{
|
||||
// Built-in found
|
||||
let context = (self, name, None, &*global, lib, pos, level + 1).into();
|
||||
let result = func(context, operands);
|
||||
@@ -278,7 +284,7 @@ impl Engine {
|
||||
args,
|
||||
*hashes,
|
||||
expr.capture_parent_scope,
|
||||
expr.is_native_operator,
|
||||
expr.operator_token.as_ref(),
|
||||
pos,
|
||||
level,
|
||||
)
|
||||
@@ -384,9 +390,9 @@ impl Engine {
|
||||
|
||||
op_info.pos = expr.start_position();
|
||||
|
||||
if let Err(err) = self
|
||||
.eval_op_assignment(global, caches, lib, op_info, target, root, item, level)
|
||||
{
|
||||
if let Err(err) = self.eval_op_assignment(
|
||||
global, caches, lib, &op_info, target, root, item, level,
|
||||
) {
|
||||
result = Err(err);
|
||||
break;
|
||||
}
|
||||
|
@@ -117,7 +117,7 @@ impl Engine {
|
||||
global: &mut GlobalRuntimeState,
|
||||
caches: &mut Caches,
|
||||
lib: &[&Module],
|
||||
op_info: OpAssignment,
|
||||
op_info: &OpAssignment,
|
||||
target: &mut Target,
|
||||
root: (&str, Position),
|
||||
new_val: Dynamic,
|
||||
@@ -141,14 +141,15 @@ impl Engine {
|
||||
|
||||
let mut lock_guard = target.write_lock::<Dynamic>().unwrap();
|
||||
|
||||
let hash = hash_op_assign;
|
||||
let hash = *hash_op_assign;
|
||||
let args = &mut [&mut *lock_guard, &mut new_val];
|
||||
let level = level + 1;
|
||||
|
||||
if self.fast_operators() {
|
||||
if let Some(func) = get_builtin_op_assignment_fn(op_assign, args[0], args[1]) {
|
||||
// Built-in found
|
||||
let context = (self, op_assign, None, &*global, lib, op_pos, level).into();
|
||||
let op = op_assign.literal_syntax();
|
||||
let context = (self, op, None, &*global, lib, *op_pos, level).into();
|
||||
let result = func(context, args).map(|_| ());
|
||||
|
||||
#[cfg(not(feature = "unchecked"))]
|
||||
@@ -158,8 +159,11 @@ impl Engine {
|
||||
}
|
||||
}
|
||||
|
||||
let op_assign = op_assign.literal_syntax();
|
||||
let op = op.literal_syntax();
|
||||
|
||||
match self.call_native_fn(
|
||||
global, caches, lib, op_assign, hash, args, true, true, op_pos, level,
|
||||
global, caches, lib, op_assign, hash, args, true, true, *op_pos, level,
|
||||
) {
|
||||
Ok(_) => {
|
||||
#[cfg(not(feature = "unchecked"))]
|
||||
@@ -170,7 +174,7 @@ impl Engine {
|
||||
// Expand to `var = var op rhs`
|
||||
*args[0] = self
|
||||
.call_native_fn(
|
||||
global, caches, lib, op, hash_op, args, true, false, op_pos, level,
|
||||
global, caches, lib, op, *hash_op, args, true, false, *op_pos, level,
|
||||
)
|
||||
.map_err(|err| err.fill_position(op_info.pos))?
|
||||
.0
|
||||
@@ -279,7 +283,7 @@ impl Engine {
|
||||
let lhs_ptr = &mut lhs_ptr;
|
||||
|
||||
self.eval_op_assignment(
|
||||
global, caches, lib, *op_info, lhs_ptr, root, rhs_val, level,
|
||||
global, caches, lib, op_info, lhs_ptr, root, rhs_val, level,
|
||||
)
|
||||
.map(|_| Dynamic::UNIT)
|
||||
} else {
|
||||
@@ -303,7 +307,7 @@ impl Engine {
|
||||
rhs_val
|
||||
};
|
||||
|
||||
let _new_val = Some((rhs_val, *op_info));
|
||||
let _new_val = Some((rhs_val, op_info));
|
||||
|
||||
// Must be either `var[index] op= val` or `var.prop op= val`
|
||||
match lhs {
|
||||
|
Reference in New Issue
Block a user