From 823013349ffc58e243560f21886152cc62917f1d Mon Sep 17 00:00:00 2001 From: Oliver Schneider Date: Wed, 30 May 2018 12:06:16 +0200 Subject: [PATCH] Pull a layout computation out of a loop --- src/librustc_mir/interpret/terminator/mod.rs | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/librustc_mir/interpret/terminator/mod.rs b/src/librustc_mir/interpret/terminator/mod.rs index cc250fb68c9..634a0c9ada8 100644 --- a/src/librustc_mir/interpret/terminator/mod.rs +++ b/src/librustc_mir/interpret/terminator/mod.rs @@ -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; }