diff options
| author | Oliver Schneider <github35764891676564198441@oli-obk.de> | 2018-05-30 12:06:16 +0200 |
|---|---|---|
| committer | Oliver Schneider <github35764891676564198441@oli-obk.de> | 2018-05-31 10:22:45 +0200 |
| commit | 823013349ffc58e243560f21886152cc62917f1d (patch) | |
| tree | 5a59a0b9dfe130c1bdbed0291593a95684498f04 /src/librustc_mir/interpret | |
| parent | 1236d57d841a8bd66c47202b8dddd13e269c8e6e (diff) | |
| download | rust-823013349ffc58e243560f21886152cc62917f1d.tar.gz rust-823013349ffc58e243560f21886152cc62917f1d.zip | |
Pull a layout computation out of a loop
Diffstat (limited to 'src/librustc_mir/interpret')
| -rw-r--r-- | src/librustc_mir/interpret/terminator/mod.rs | 5 |
1 files changed, 4 insertions, 1 deletions
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; } |
