Refactor how SwitchInt stores jump targets

This commit is contained in:
Jonas Schievink
2020-10-10 17:36:04 +02:00
parent cae8bc1f23
commit 432535da2b
22 changed files with 247 additions and 206 deletions

View File

@@ -29,17 +29,16 @@ impl<'tcx> MirPass<'tcx> for SimplifyBranches {
TerminatorKind::SwitchInt {
discr: Operand::Constant(ref c),
switch_ty,
ref values,
ref targets,
..
} => {
let constant = c.literal.try_eval_bits(tcx, param_env, switch_ty);
if let Some(constant) = constant {
let (otherwise, targets) = targets.split_last().unwrap();
let mut ret = TerminatorKind::Goto { target: *otherwise };
for (&v, t) in values.iter().zip(targets.iter()) {
let otherwise = targets.otherwise();
let mut ret = TerminatorKind::Goto { target: otherwise };
for (v, t) in targets.iter() {
if v == constant {
ret = TerminatorKind::Goto { target: *t };
ret = TerminatorKind::Goto { target: t };
break;
}
}