Auto merge of #124190 - RalfJung:pat-compare-with-fast-path, r=Nadrieril
PatRangeBoundary::compare_with: als add a fast-path for signed integers Not sure if we have a benchmark that hits this... but it seems odd to only do this for unsigned integers.
This commit is contained in:
commit
c3ceb00281
1 changed files with 8 additions and 5 deletions
|
@ -1006,15 +1006,18 @@ impl<'tcx> PatRangeBoundary<'tcx> {
|
||||||
|
|
||||||
// This code is hot when compiling matches with many ranges. So we
|
// This code is hot when compiling matches with many ranges. So we
|
||||||
// special-case extraction of evaluated scalars for speed, for types where
|
// 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
|
// many ranges such as '\u{037A}'..='\u{037F}', and chars can be compared
|
||||||
// in this way.
|
// 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()) {
|
if let (Some(a), Some(b)) = (a.try_to_scalar_int(), b.try_to_scalar_int()) {
|
||||||
let sz = ty.primitive_size(tcx);
|
let sz = ty.primitive_size(tcx);
|
||||||
let a = a.assert_uint(sz);
|
let cmp = match ty.kind() {
|
||||||
let b = b.assert_uint(sz);
|
ty::Uint(_) | ty::Char => a.assert_uint(sz).cmp(&b.assert_uint(sz)),
|
||||||
return Some(a.cmp(&b));
|
ty::Int(_) => a.assert_int(sz).cmp(&b.assert_int(sz)),
|
||||||
|
_ => unreachable!(),
|
||||||
|
};
|
||||||
|
return Some(cmp);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
_ => {}
|
_ => {}
|
||||||
|
|
Loading…
Add table
Reference in a new issue