Skip to content

Commit 8230133

Browse files
committed
Pull a layout computation out of a loop
1 parent 1236d57 commit 8230133

File tree

1 file changed

+4
-1
lines changed
  • src/librustc_mir/interpret/terminator

1 file changed

+4
-1
lines changed

src/librustc_mir/interpret/terminator/mod.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,12 +39,15 @@ impl<'a, 'mir, 'tcx, M: Machine<'mir, 'tcx>> EvalContext<'a, 'mir, 'tcx, M> {
3939
} => {
4040
let discr_val = self.eval_operand(discr)?;
4141
let discr_prim = self.value_to_scalar(discr_val)?;
42+
let discr_layout = self.layout_of(discr_val.ty).unwrap();
43+
trace!("SwitchInt({:?}, {:#?})", discr_prim, discr_layout);
44+
let discr_prim = discr_prim.to_bits(discr_layout.size)?;
4245

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

4649
for (index, &const_int) in values.iter().enumerate() {
47-
if discr_prim.to_bits(self.layout_of(discr_val.ty).unwrap().size)? == const_int {
50+
if discr_prim == const_int {
4851
target_block = targets[index];
4952
break;
5053
}

0 commit comments

Comments
 (0)