diff options
| author | Ralf Jung <post@ralfj.de> | 2024-04-20 08:30:19 +0200 |
|---|---|---|
| committer | Ralf Jung <post@ralfj.de> | 2024-04-20 08:34:57 +0200 |
| commit | 727fe81fd6f1c52e7858e6e248bda1a607c7fabf (patch) | |
| tree | 9ccc631e7ca50b2aa91ce514d0459b712a3848a2 | |
| parent | c8d19a92aa9022eb690899cf6d54fd23cb6877e5 (diff) | |
PatRangeBoundary::compare_with: als add a fast-path for signed integers
| -rw-r--r-- | compiler/rustc_middle/src/thir.rs | 13 |
1 files changed, 8 insertions, 5 deletions
diff --git a/compiler/rustc_middle/src/thir.rs b/compiler/rustc_middle/src/thir.rs index 66130a8dde0..d52b1efce4b 100644 --- a/compiler/rustc_middle/src/thir.rs +++ b/compiler/rustc_middle/src/thir.rs @@ -1006,15 +1006,18 @@ impl<'tcx> PatRangeBoundary<'tcx> { // This code is hot when compiling matches with many ranges. So we // special-case extraction of evaluated scalars for speed, for types where - // unsigned int comparisons are appropriate. E.g. `unicode-normalization` has + // we can do scalar comparisons. E.g. `unicode-normalization` has // many ranges such as '\u{037A}'..='\u{037F}', and chars can be compared // in this way. - (Finite(a), Finite(b)) if matches!(ty.kind(), ty::Uint(_) | ty::Char) => { + (Finite(a), Finite(b)) if matches!(ty.kind(), ty::Int(_) | ty::Uint(_) | ty::Char) => { if let (Some(a), Some(b)) = (a.try_to_scalar_int(), b.try_to_scalar_int()) { let sz = ty.primitive_size(tcx); - let a = a.assert_uint(sz); - let b = b.assert_uint(sz); - return Some(a.cmp(&b)); + let cmp = match ty.kind() { + ty::Uint(_) | ty::Char => a.assert_uint(sz).cmp(&b.assert_uint(sz)), + ty::Int(_) => a.assert_int(sz).cmp(&b.assert_int(sz)), + _ => unreachable!(), + }; + return Some(cmp); } } _ => {} |
