Skip to content

Commit 1ed8ff2

Browse files
committed
try to improve perf
1 parent b9ebde5 commit 1ed8ff2

File tree

1 file changed

+8
-3
lines changed

1 file changed

+8
-3
lines changed

compiler/rustc_middle/src/thir.rs

+8-3
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ use rustc_hir::{BindingAnnotation, ByRef, HirId, MatchSource, RangeEnd};
1616
use rustc_index::newtype_index;
1717
use rustc_index::IndexVec;
1818
use rustc_middle::middle::region;
19-
use rustc_middle::mir::interpret::AllocId;
19+
use rustc_middle::mir::interpret::{AllocId, Scalar};
2020
use rustc_middle::mir::{self, BinOp, BorrowKind, FakeReadCause, UnOp};
2121
use rustc_middle::ty::adjustment::PointerCoercion;
2222
use rustc_middle::ty::layout::IntegerExt;
@@ -1009,11 +1009,16 @@ impl<'tcx> PatRangeBoundary<'tcx> {
10091009

10101010
// This code is hot when compiling matches with many ranges. So we
10111011
// special-case extraction of evaluated scalars for speed, for types where
1012-
// raw data comparisons are appropriate. E.g. `unicode-normalization` has
1012+
// unsigned int comparisons are appropriate. E.g. `unicode-normalization` has
10131013
// many ranges such as '\u{037A}'..='\u{037F}', and chars can be compared
10141014
// in this way.
10151015
(Finite(a), Finite(b)) if matches!(ty.kind(), ty::Uint(_) | ty::Char) => {
1016-
if let (Some(a), Some(b)) = (a.try_to_scalar_int(), b.try_to_scalar_int()) {
1016+
let to_scalar_int = |x| match x {
1017+
mir::Const::Val(mir::ConstValue::Scalar(Scalar::Int(x)), _) => Some(x),
1018+
mir::Const::Ty(x) => Some(x.to_valtree().unwrap_leaf()),
1019+
_ => None,
1020+
};
1021+
if let (Some(a), Some(b)) = (to_scalar_int(a), to_scalar_int(b)) {
10171022
let sz = ty.primitive_size(tcx);
10181023
let a = a.assert_uint(sz);
10191024
let b = b.assert_uint(sz);

0 commit comments

Comments
 (0)