Skip to content

Commit

Permalink
Pull a layout computation out of a loop
Browse files Browse the repository at this point in the history
  • Loading branch information
oli-obk committed May 31, 2018
1 parent 1236d57 commit 8230133
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion src/librustc_mir/interpret/terminator/mod.rs
Expand Up @@ -39,12 +39,15 @@ impl<'a, 'mir, 'tcx, M: Machine<'mir, 'tcx>> EvalContext<'a, 'mir, 'tcx, M> {
} => {
let discr_val = self.eval_operand(discr)?;
let discr_prim = self.value_to_scalar(discr_val)?;
let discr_layout = self.layout_of(discr_val.ty).unwrap();
trace!("SwitchInt({:?}, {:#?})", discr_prim, discr_layout);
let discr_prim = discr_prim.to_bits(discr_layout.size)?;

// Branch to the `otherwise` case by default, if no match is found.
let mut target_block = targets[targets.len() - 1];

for (index, &const_int) in values.iter().enumerate() {
if discr_prim.to_bits(self.layout_of(discr_val.ty).unwrap().size)? == const_int {
if discr_prim == const_int {
target_block = targets[index];
break;
}
Expand Down

0 comments on commit 8230133

Please sign in to comment.