diff --git a/src/eval/mod.rs b/src/eval/mod.rs index 443000e9..814baaf2 100644 --- a/src/eval/mod.rs +++ b/src/eval/mod.rs @@ -11,8 +11,10 @@ mod target; pub use cache::{Caches, FnResolutionCache, FnResolutionCacheEntry}; #[cfg(any(not(feature = "no_index"), not(feature = "no_object")))] pub use chaining::ChainType; +#[cfg(not(feature = "unchecked"))] #[cfg(not(feature = "no_index"))] pub use data_check::calc_array_sizes; +#[cfg(not(feature = "unchecked"))] #[cfg(not(feature = "no_object"))] pub use data_check::calc_map_sizes; #[cfg(feature = "debugging")] diff --git a/src/func/call.rs b/src/func/call.rs index 687ed3fc..d9928fdf 100644 --- a/src/func/call.rs +++ b/src/func/call.rs @@ -1576,6 +1576,11 @@ impl Engine { .0 .flatten(); + match value.0 { + Union::Bool(b, ..) => return Ok((!b).into()), + _ => (), + } + return value.as_bool().map(|r| (!r).into()).or_else(|_| { let operand = &mut [&mut value]; self.exec_fn_call( @@ -1597,6 +1602,8 @@ impl Engine { .0 .flatten(); + // For extremely simple primary data operations, do it directly + // to avoid the overhead of calling a function. match (&lhs.0, &rhs.0) { (Union::Unit(..), Union::Unit(..)) => match op_token.unwrap() { Token::EqualsTo => return Ok(Dynamic::TRUE), @@ -1623,6 +1630,7 @@ impl Engine { #[allow(clippy::wildcard_imports)] use crate::packages::arithmetic::arith_basic::INT::functions::*; + #[cfg(not(feature = "unchecked"))] match op_token.unwrap() { Token::EqualsTo => return Ok((*n1 == *n2).into()), Token::NotEqualsTo => return Ok((*n1 != *n2).into()), @@ -1630,29 +1638,26 @@ impl Engine { Token::GreaterThanEqualsTo => return Ok((*n1 >= *n2).into()), Token::LessThan => return Ok((*n1 < *n2).into()), Token::LessThanEqualsTo => return Ok((*n1 <= *n2).into()), - - #[cfg(not(feature = "unchecked"))] Token::Plus => return add(*n1, *n2).map(Into::into), - #[cfg(not(feature = "unchecked"))] Token::Minus => return subtract(*n1, *n2).map(Into::into), - #[cfg(not(feature = "unchecked"))] Token::Multiply => return multiply(*n1, *n2).map(Into::into), - #[cfg(not(feature = "unchecked"))] Token::Divide => return divide(*n1, *n2).map(Into::into), - #[cfg(not(feature = "unchecked"))] Token::Modulo => return modulo(*n1, *n2).map(Into::into), - - #[cfg(feature = "unchecked")] + _ => (), + } + #[cfg(feature = "unchecked")] + match op_token.unwrap() { + Token::EqualsTo => return Ok((*n1 == *n2).into()), + Token::NotEqualsTo => return Ok((*n1 != *n2).into()), + Token::GreaterThan => return Ok((*n1 > *n2).into()), + Token::GreaterThanEqualsTo => return Ok((*n1 >= *n2).into()), + Token::LessThan => return Ok((*n1 < *n2).into()), + Token::LessThanEqualsTo => return Ok((*n1 <= *n2).into()), Token::Plus => return Ok((*n1 + *n2).into()), - #[cfg(feature = "unchecked")] Token::Minus => return Ok((*n1 - *n2).into()), - #[cfg(feature = "unchecked")] Token::Multiply => return Ok((*n1 * *n2).into()), - #[cfg(feature = "unchecked")] Token::Divide => return Ok((*n1 / *n2).into()), - #[cfg(feature = "unchecked")] Token::Modulo => return Ok((*n1 % *n2).into()), - _ => (), } } diff --git a/src/packages/array_basic.rs b/src/packages/array_basic.rs index c8cb1a86..6e2c2089 100644 --- a/src/packages/array_basic.rs +++ b/src/packages/array_basic.rs @@ -2,7 +2,7 @@ use crate::api::deprecated::deprecated_array_functions; use crate::engine::OP_EQUALS; -use crate::eval::{calc_index, calc_offset_len, calc_array_sizes}; +use crate::eval::{calc_index, calc_offset_len}; use crate::module::ModuleFlags; use crate::plugin::*; @@ -238,7 +238,7 @@ pub mod array_functions { #[cfg(not(feature = "unchecked"))] if _ctx.engine().max_array_size() > 0 { let pad = len - array.len(); - let (a, m, s) = calc_array_sizes(array); + let (a, m, s) = crate::eval::calc_array_sizes(array); let (ax, mx, sx) = item.calc_data_sizes(true); _ctx.engine()