Hard code constant checking.

This commit is contained in:
Stephen Chung
2022-12-03 16:20:13 +08:00
parent ffc8a7f85c
commit 55922b5c20
16 changed files with 474 additions and 374 deletions

View File

@@ -1137,8 +1137,12 @@ fn optimize_expr(expr: &mut Expr, state: &mut OptimizerState, _chaining: bool) {
// Overloaded operators can override built-in.
_ if x.args.len() == 2 && x.op_token != Token::NONE && (state.engine.fast_operators() || !state.engine.has_native_fn_override(x.hashes.native(), &arg_types)) => {
if let Some(result) = get_builtin_binary_op_fn(x.op_token.clone(), &arg_values[0], &arg_values[1])
.and_then(|f| {
let context = (state.engine, x.name.as_str(),None, &state.global, *pos).into();
.and_then(|(f, ctx)| {
let context = if ctx {
Some((state.engine, x.name.as_str(),None, &state.global, *pos).into())
} else {
None
};
let (first, second) = arg_values.split_first_mut().unwrap();
(f)(context, &mut [ first, &mut second[0] ]).ok()
}) {