Use standard operator to short-circuit.

This commit is contained in:
Stephen Chung 2022-09-03 12:35:00 +08:00
parent 75512bfd2f
commit 43c4d7e3ca
2 changed files with 7 additions and 4 deletions

View File

@ -222,14 +222,14 @@ impl Engine {
#[cfg(not(feature = "no_module"))] #[cfg(not(feature = "no_module"))]
namespace, namespace,
capture_parent_scope: capture, capture_parent_scope: capture,
is_standard_operator, is_standard_operator: std_ops,
hashes, hashes,
args, args,
.. ..
} = expr; } = expr;
#[cfg(feature = "fast_ops")] #[cfg(feature = "fast_ops")]
if *is_standard_operator { if *std_ops {
let mut lhs = self let mut lhs = self
.get_arg_value(scope, global, caches, lib, this_ptr, &args[0], level)? .get_arg_value(scope, global, caches, lib, this_ptr, &args[0], level)?
.0 .0
@ -311,8 +311,8 @@ impl Engine {
); );
self.make_function_call( self.make_function_call(
scope, global, caches, lib, this_ptr, name, first_arg, args, *hashes, *capture, pos, scope, global, caches, lib, this_ptr, name, first_arg, args, *hashes, *capture,
level, *std_ops, pos, level,
) )
} }

View File

@ -989,6 +989,7 @@ impl Engine {
args_expr: &[Expr], args_expr: &[Expr],
hashes: FnCallHashes, hashes: FnCallHashes,
capture_scope: bool, capture_scope: bool,
is_standard_operator: bool,
pos: Position, pos: Position,
level: usize, level: usize,
) -> RhaiResult { ) -> RhaiResult {
@ -1001,6 +1002,8 @@ impl Engine {
let redirected; // Handle call() - Redirect function call let redirected; // Handle call() - Redirect function call
match name { match name {
_ if is_standard_operator => (),
// Handle call() // Handle call()
KEYWORD_FN_PTR_CALL if total_args >= 1 => { KEYWORD_FN_PTR_CALL if total_args >= 1 => {
let arg = first_arg.unwrap(); let arg = first_arg.unwrap();