@@ -227,15 +227,18 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
227
227
_ => ( None , 0 ) ,
228
228
} ;
229
229
if let Some ( ( min, max, sz) ) = range {
230
- if let ( Some ( lo) , Some ( hi) ) = ( lo. try_to_bits ( sz) , hi. try_to_bits ( sz) ) {
231
- // We want to compare ranges numerically, but the order of the bitwise
232
- // representation of signed integers does not match their numeric order.
233
- // Thus, to correct the ordering, we need to shift the range of signed
234
- // integers to correct the comparison. This is achieved by XORing with a
235
- // bias (see pattern/_match.rs for another pertinent example of this
236
- // pattern).
237
- let ( lo, hi) = ( lo ^ bias, hi ^ bias) ;
238
- if lo <= min && ( hi > max || hi == max && end == RangeEnd :: Included ) {
230
+ // We want to compare ranges numerically, but the order of the bitwise
231
+ // representation of signed integers does not match their numeric order. Thus,
232
+ // to correct the ordering, we need to shift the range of signed integers to
233
+ // correct the comparison. This is achieved by XORing with a bias (see
234
+ // pattern/_match.rs for another pertinent example of this pattern).
235
+ //
236
+ // Also, for performance, it's important to only do the second `try_to_bits` if
237
+ // necessary.
238
+ let lo = lo. try_to_bits ( sz) . unwrap ( ) ^ bias;
239
+ if lo <= min {
240
+ let hi = hi. try_to_bits ( sz) . unwrap ( ) ^ bias;
241
+ if hi > max || hi == max && end == RangeEnd :: Included {
239
242
// Irrefutable pattern match.
240
243
return Ok ( ( ) ) ;
241
244
}
0 commit comments