Code style refactor.

This commit is contained in:
Stephen Chung
2021-05-25 10:54:48 +08:00
parent 58d6a88bc4
commit dfea3ed22a
11 changed files with 266 additions and 413 deletions

View File

@@ -504,12 +504,13 @@ fn optimize_stmt(stmt: &mut Stmt, state: &mut State, preserve_result: bool) {
Stmt::Switch(match_expr, x, _) => {
optimize_expr(match_expr, state);
x.0.values_mut().for_each(|block| {
let condition = if let Some(mut condition) = mem::take(&mut block.0) {
optimize_expr(&mut condition, state);
condition
} else {
Expr::Unit(Position::NONE)
};
let condition = mem::take(&mut block.0).map_or_else(
|| Expr::Unit(Position::NONE),
|mut condition| {
optimize_expr(&mut condition, state);
condition
},
);
match condition {
Expr::Unit(_) | Expr::BoolConstant(true, _) => (),