From 7a67563cbd225c430518cc4e8989defbf010a70c Mon Sep 17 00:00:00 2001 From: Shoumik Palkar Date: Mon, 19 Aug 2019 17:40:59 -0700 Subject: [PATCH] Remove clones from short circuit booleans pass (#467) --- .../src/optimizer/transforms/short_circuit.rs | 35 +++++++++---------- 1 file changed, 17 insertions(+), 18 deletions(-) diff --git a/weld/src/optimizer/transforms/short_circuit.rs b/weld/src/optimizer/transforms/short_circuit.rs index 16fa17a3e..8567fb3e5 100644 --- a/weld/src/optimizer/transforms/short_circuit.rs +++ b/weld/src/optimizer/transforms/short_circuit.rs @@ -1,4 +1,3 @@ -use crate::ast::constructors::*; use crate::ast::ExprKind::*; use crate::ast::*; @@ -28,36 +27,36 @@ pub fn short_circuit_booleans(expr: &mut Expr) { return; } - let new = match expr.kind { + let replaced = match expr.kind { BinOp { - ref kind, - ref left, - ref right, + ref mut kind, + ref mut left, + ref mut right, } if *kind == BinOpKind::LogicalAnd => Some( - if_expr( - left.as_ref().clone(), - right.as_ref().clone(), - literal_expr(LiteralKind::BoolLiteral(false)).unwrap(), + Expr::new_if( + *left.take(), + *right.take(), + Expr::new_literal(LiteralKind::BoolLiteral(false)).unwrap(), ) .unwrap(), ), BinOp { - ref kind, - ref left, - ref right, + ref mut kind, + ref mut left, + ref mut right, } if *kind == BinOpKind::LogicalOr => Some( - if_expr( - left.as_ref().clone(), - literal_expr(LiteralKind::BoolLiteral(true)).unwrap(), - right.as_ref().clone(), + Expr::new_if( + *left.take(), + Expr::new_literal(LiteralKind::BoolLiteral(true)).unwrap(), + *right.take(), ) .unwrap(), ), _ => None, }; - if let Some(new) = new { - *expr = new; + if let Some(replaced) = replaced { + *expr = replaced; } for child in expr.children_mut() {