Skip to content

Commit d48c130

Browse files
committed
Raise the aggregate equality comparison threshold so simple arrays don't get captured by this logic
1 parent dd7c6c9 commit d48c130

1 file changed

Lines changed: 7 additions & 2 deletions

File tree

compiler/rustc_mir_build/src/builder/matches/match_pair.rs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,11 @@ use crate::builder::matches::{
1313
FlatPat, MatchPairTree, PatConstKind, PatternExtraData, SliceLenOp, TestableCase,
1414
};
1515

16+
/// Below this length, an array or slice pattern is compared element by element
17+
/// rather than as a single aggregate, since the per-element comparisons are
18+
/// unlikely to be more expensive than a `PartialEq::eq` call.
19+
const AGGREGATE_EQ_MIN_LEN: usize = 4;
20+
1621
/// Checks whether every pattern in `elements` is a `PatKind::Constant` and,
1722
/// if so, reconstructs a single aggregate `ty::Value` that represents the whole
1823
/// array or slice. Returns `None` when any element is not a constant or the
@@ -22,8 +27,8 @@ fn try_reconstruct_aggregate_constant<'tcx>(
2227
aggregate_ty: Ty<'tcx>,
2328
elements: &[Pat<'tcx>],
2429
) -> Option<ty::Value<'tcx>> {
25-
// A single element (or empty array) is not worth an aggregate comparison.
26-
if elements.len() <= 1 {
30+
// Short arrays are not worth an aggregate comparison.
31+
if elements.len() < AGGREGATE_EQ_MIN_LEN {
2732
return None;
2833
}
2934
let branches = elements

0 commit comments

Comments
 (0)