Avoid double checking of builtin's.
This commit is contained in:
parent
baaa0461bf
commit
02057ef1d2
@ -21,6 +21,7 @@ use crate::stdlib::{
|
|||||||
string::ToString,
|
string::ToString,
|
||||||
vec::Vec,
|
vec::Vec,
|
||||||
};
|
};
|
||||||
|
use crate::token::is_assignment_operator;
|
||||||
use crate::utils::combine_hashes;
|
use crate::utils::combine_hashes;
|
||||||
use crate::{
|
use crate::{
|
||||||
calc_native_fn_hash, calc_script_fn_hash, Dynamic, Engine, EvalAltResult, FnPtr,
|
calc_native_fn_hash, calc_script_fn_hash, Dynamic, Engine, EvalAltResult, FnPtr,
|
||||||
@ -285,17 +286,9 @@ impl Engine {
|
|||||||
|
|
||||||
// See if it is built in.
|
// See if it is built in.
|
||||||
if args.len() == 2 && !args[0].is_variant() && !args[1].is_variant() {
|
if args.len() == 2 && !args[0].is_variant() && !args[1].is_variant() {
|
||||||
match run_builtin_binary_op(fn_name, args[0], args[1])? {
|
if is_assignment_operator(fn_name) {
|
||||||
Some(v) => return Ok((v, false)),
|
|
||||||
None => (),
|
|
||||||
}
|
|
||||||
|
|
||||||
// Op-assignment?
|
|
||||||
if is_ref {
|
if is_ref {
|
||||||
match fn_name {
|
// Op-assignment
|
||||||
_ if fn_name.len() <= 1 => (),
|
|
||||||
"==" | "!=" | ">=" | "<=" => (),
|
|
||||||
_ if fn_name.ends_with('=') => {
|
|
||||||
let (first, second) = args.split_first_mut().unwrap();
|
let (first, second) = args.split_first_mut().unwrap();
|
||||||
|
|
||||||
match run_builtin_op_assignment(fn_name, first, second[0])? {
|
match run_builtin_op_assignment(fn_name, first, second[0])? {
|
||||||
@ -303,7 +296,10 @@ impl Engine {
|
|||||||
None => (),
|
None => (),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
_ => (),
|
} else {
|
||||||
|
match run_builtin_binary_op(fn_name, args[0], args[1])? {
|
||||||
|
Some(v) => return Ok((v, false)),
|
||||||
|
None => (),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
12
src/token.rs
12
src/token.rs
@ -1657,24 +1657,36 @@ pub fn is_valid_identifier(name: impl Iterator<Item = char>) -> bool {
|
|||||||
first_alphabetic
|
first_alphabetic
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Is a text string an assignment operator?
|
||||||
|
pub fn is_assignment_operator(op: &str) -> bool {
|
||||||
|
match op {
|
||||||
|
"+=" | "-=" | "*=" | "/=" | "<<=" | ">>=" | "&=" | "|=" | "^=" | "%=" | "**=" => true,
|
||||||
|
_ => false,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Is a character valid to start an identifier?
|
||||||
#[cfg(feature = "unicode-xid-ident")]
|
#[cfg(feature = "unicode-xid-ident")]
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
pub fn is_id_first_alphabetic(x: char) -> bool {
|
pub fn is_id_first_alphabetic(x: char) -> bool {
|
||||||
unicode_xid::UnicodeXID::is_xid_start(x)
|
unicode_xid::UnicodeXID::is_xid_start(x)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Is a character valid for an identifier?
|
||||||
#[cfg(feature = "unicode-xid-ident")]
|
#[cfg(feature = "unicode-xid-ident")]
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
pub fn is_id_continue(x: char) -> bool {
|
pub fn is_id_continue(x: char) -> bool {
|
||||||
unicode_xid::UnicodeXID::is_xid_continue(x)
|
unicode_xid::UnicodeXID::is_xid_continue(x)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Is a character valid to start an identifier?
|
||||||
#[cfg(not(feature = "unicode-xid-ident"))]
|
#[cfg(not(feature = "unicode-xid-ident"))]
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
pub fn is_id_first_alphabetic(x: char) -> bool {
|
pub fn is_id_first_alphabetic(x: char) -> bool {
|
||||||
x.is_ascii_alphabetic()
|
x.is_ascii_alphabetic()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Is a character valid for an identifier?
|
||||||
#[cfg(not(feature = "unicode-xid-ident"))]
|
#[cfg(not(feature = "unicode-xid-ident"))]
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
pub fn is_id_continue(x: char) -> bool {
|
pub fn is_id_continue(x: char) -> bool {
|
||||||
|
Loading…
Reference in New Issue
Block a user