Small optimization
Optimiize ExprKind::EmptyToAny expressions applied to function calls.
This commit is contained in:
parent
798f719daf
commit
533a389962
@ -46,12 +46,24 @@ impl<'a, 'gcx, 'tcx> Builder<'a, 'gcx, 'tcx> {
|
||||
this.match_expr(destination, expr_span, block, discriminant, arms)
|
||||
}
|
||||
ExprKind::EmptyToAny { source } => {
|
||||
// TODO(canndrew): Do we need to do this?
|
||||
let source = this.hir.mirror(source);
|
||||
let is_call = match source.kind {
|
||||
ExprKind::Call { .. } => true,
|
||||
_ => false,
|
||||
};
|
||||
|
||||
unpack!(block = this.as_rvalue(block, source));
|
||||
|
||||
this.cfg.terminate(block, source_info, TerminatorKind::Unreachable);
|
||||
let end_block = this.cfg.start_new_block();
|
||||
end_block.unit()
|
||||
// This is an optimization. If the expression was a call then we already have an
|
||||
// unreachable block. Don't bother to terminate it and create a new one.
|
||||
if is_call {
|
||||
block.unit()
|
||||
}
|
||||
else {
|
||||
this.cfg.terminate(block, source_info, TerminatorKind::Unreachable);
|
||||
let end_block = this.cfg.start_new_block();
|
||||
end_block.unit()
|
||||
}
|
||||
}
|
||||
ExprKind::If { condition: cond_expr, then: then_expr, otherwise: else_expr } => {
|
||||
let operand = unpack!(block = this.as_operand(block, cond_expr));
|
||||
|
Loading…
Reference in New Issue
Block a user