Use &Token for op.

This commit is contained in:
Stephen Chung
2023-02-10 23:42:13 +08:00
parent 8d1fa19331
commit 4fe80a2026
6 changed files with 18 additions and 18 deletions

View File

@@ -86,7 +86,7 @@ fn const_false_fn(_: Option<NativeCallContext>, _: &mut [&mut Dynamic]) -> RhaiR
///
/// The return function will be registered as a _method_, so the first parameter cannot be consumed.
#[must_use]
pub fn get_builtin_binary_op_fn(op: Token, x: &Dynamic, y: &Dynamic) -> Option<FnBuiltin> {
pub fn get_builtin_binary_op_fn(op: &Token, x: &Dynamic, y: &Dynamic) -> Option<FnBuiltin> {
let type1 = x.type_id();
let type2 = y.type_id();
@@ -621,7 +621,7 @@ pub fn get_builtin_binary_op_fn(op: Token, x: &Dynamic, y: &Dynamic) -> Option<F
///
/// The return function is registered as a _method_, so the first parameter cannot be consumed.
#[must_use]
pub fn get_builtin_op_assignment_fn(op: Token, x: &Dynamic, y: &Dynamic) -> Option<FnBuiltin> {
pub fn get_builtin_op_assignment_fn(op: &Token, x: &Dynamic, y: &Dynamic) -> Option<FnBuiltin> {
let type1 = x.type_id();
let type2 = y.type_id();

View File

@@ -164,7 +164,7 @@ impl Engine {
_global: &GlobalRuntimeState,
caches: &'s mut Caches,
local_entry: &'s mut Option<FnResolutionCacheEntry>,
op_token: Option<Token>,
op_token: Option<&Token>,
hash_base: u64,
args: Option<&mut FnCallArgs>,
allow_dynamic: bool,
@@ -345,7 +345,7 @@ impl Engine {
global: &mut GlobalRuntimeState,
caches: &mut Caches,
name: &str,
op_token: Option<Token>,
op_token: Option<&Token>,
hash: u64,
args: &mut FnCallArgs,
is_ref_mut: bool,
@@ -567,7 +567,7 @@ impl Engine {
caches: &mut Caches,
_scope: Option<&mut Scope>,
fn_name: &str,
op_token: Option<Token>,
op_token: Option<&Token>,
hashes: FnCallHashes,
mut _args: &mut FnCallArgs,
is_ref_mut: bool,
@@ -1000,7 +1000,7 @@ impl Engine {
scope: &mut Scope,
mut this_ptr: Option<&mut Dynamic>,
fn_name: &str,
op_token: Option<Token>,
op_token: Option<&Token>,
first_arg: Option<&Expr>,
args_expr: &[Expr],
hashes: FnCallHashes,
@@ -1564,10 +1564,10 @@ impl Engine {
..
} = expr;
let op_token = op_token.clone();
let op_token = op_token.as_ref();
// Short-circuit native unary operator call if under Fast Operators mode
if op_token == Some(Token::Bang) && self.fast_operators() && args.len() == 1 {
if op_token == Some(&Token::Bang) && self.fast_operators() && args.len() == 1 {
let mut value = self
.get_arg_value(global, caches, scope, this_ptr.as_deref_mut(), &args[0])?
.0
@@ -1597,7 +1597,7 @@ impl Engine {
let operands = &mut [&mut lhs, &mut rhs];
if let Some((func, need_context)) =
get_builtin_binary_op_fn(op_token.clone().unwrap(), operands[0], operands[1])
get_builtin_binary_op_fn(op_token.as_ref().unwrap(), operands[0], operands[1])
{
// Built-in found
auto_restore! { let orig_level = global.level; global.level += 1 }

View File

@@ -446,7 +446,7 @@ impl<'a> NativeCallContext<'a> {
global,
caches,
fn_name,
op_token,
op_token.as_ref(),
calc_fn_hash(None, fn_name, args_len),
args,
is_ref_mut,
@@ -473,7 +473,7 @@ impl<'a> NativeCallContext<'a> {
caches,
None,
fn_name,
op_token,
op_token.as_ref(),
hash,
args,
is_ref_mut,