Use then/then_some to simplify.

This commit is contained in:
Stephen Chung
2023-02-21 16:36:57 +08:00
parent 00f2b07d38
commit 129a5c6e86
6 changed files with 31 additions and 63 deletions

View File

@@ -1137,11 +1137,7 @@ fn optimize_expr(expr: &mut Expr, state: &mut OptimizerState, _chaining: bool) {
_ if x.args.len() == 2 && x.op_token.is_some() && (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.as_ref().unwrap(), &arg_values[0], &arg_values[1])
.and_then(|(f, ctx)| {
let context = if ctx {
Some((state.engine, x.name.as_str(), None, &state.global, *pos).into())
} else {
None
};
let context = ctx.then_some((state.engine, x.name.as_str(), None, &state.global, *pos).into());
let (first, second) = arg_values.split_first_mut().unwrap();
(f)(context, &mut [ first, &mut second[0] ]).ok()
}) {