Skip to content

Commit eee8baf

Browse files
committed
Use SmallVec for Matrix
1 parent 98a9d5c commit eee8baf

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

Diff for: compiler/rustc_mir_build/src/thir/pattern/usefulness.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -721,7 +721,7 @@ impl<'p, 'tcx> fmt::Debug for MatrixRow<'p, 'tcx> {
721721
/// the matrix will correspond to `scrutinee.0.Some.0` and the second column to `scrutinee.1`.
722722
#[derive(Clone)]
723723
struct Matrix<'p, 'tcx> {
724-
rows: Vec<MatrixRow<'p, 'tcx>>,
724+
rows: SmallVec<[MatrixRow<'p, 'tcx>; 8]>,
725725
/// Stores an extra fictitious row full of wildcards. Mostly used to keep track of the type of
726726
/// each column. This must obey the same invariants as the real rows.
727727
wildcard_row: PatStack<'p, 'tcx>,
@@ -745,7 +745,7 @@ impl<'p, 'tcx> Matrix<'p, 'tcx> {
745745
fn new(cx: &MatchCheckCtxt<'p, 'tcx>, arms: &[MatchArm<'p, 'tcx>], scrut_ty: Ty<'tcx>) -> Self {
746746
let wild_pattern = cx.pattern_arena.alloc(DeconstructedPat::wildcard(scrut_ty, DUMMY_SP));
747747
let wildcard_row = PatStack::from_pattern(cx, wild_pattern);
748-
let mut matrix = Matrix { rows: Vec::with_capacity(arms.len()), wildcard_row };
748+
let mut matrix = Matrix { rows: SmallVec::with_capacity(arms.len()), wildcard_row };
749749
for (row_id, arm) in arms.iter().enumerate() {
750750
let v = MatrixRow {
751751
pats: PatStack::from_pattern(cx, arm.pat),
@@ -809,7 +809,7 @@ impl<'p, 'tcx> Matrix<'p, 'tcx> {
809809
ctor: &Constructor<'tcx>,
810810
) -> Matrix<'p, 'tcx> {
811811
let wildcard_row = self.wildcard_row.pop_head_constructor(pcx, ctor);
812-
let rows = Vec::with_capacity(self.rows.len()); // Better waste capacity than reallocate a lot.
812+
let rows = SmallVec::with_capacity(self.rows.len()); // Better waste capacity than reallocate a lot.
813813
let mut matrix = Matrix { rows, wildcard_row };
814814
for (i, row) in self.rows().enumerate() {
815815
if ctor.is_covered_by(pcx, row.head().ctor()) {

0 commit comments

Comments
 (0)