From eee8baf4ae4a5a3d67bb66919e7455c24ec193d3 Mon Sep 17 00:00:00 2001 From: Nadrieril Date: Fri, 1 Dec 2023 08:44:37 +0100 Subject: [PATCH] Use `SmallVec` for `Matrix` --- compiler/rustc_mir_build/src/thir/pattern/usefulness.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/compiler/rustc_mir_build/src/thir/pattern/usefulness.rs b/compiler/rustc_mir_build/src/thir/pattern/usefulness.rs index 2c39e58e74526..e9fe1f2310578 100644 --- a/compiler/rustc_mir_build/src/thir/pattern/usefulness.rs +++ b/compiler/rustc_mir_build/src/thir/pattern/usefulness.rs @@ -721,7 +721,7 @@ impl<'p, 'tcx> fmt::Debug for MatrixRow<'p, 'tcx> { /// the matrix will correspond to `scrutinee.0.Some.0` and the second column to `scrutinee.1`. #[derive(Clone)] struct Matrix<'p, 'tcx> { - rows: Vec>, + rows: SmallVec<[MatrixRow<'p, 'tcx>; 8]>, /// Stores an extra fictitious row full of wildcards. Mostly used to keep track of the type of /// each column. This must obey the same invariants as the real rows. wildcard_row: PatStack<'p, 'tcx>, @@ -745,7 +745,7 @@ impl<'p, 'tcx> Matrix<'p, 'tcx> { fn new(cx: &MatchCheckCtxt<'p, 'tcx>, arms: &[MatchArm<'p, 'tcx>], scrut_ty: Ty<'tcx>) -> Self { let wild_pattern = cx.pattern_arena.alloc(DeconstructedPat::wildcard(scrut_ty, DUMMY_SP)); let wildcard_row = PatStack::from_pattern(cx, wild_pattern); - let mut matrix = Matrix { rows: Vec::with_capacity(arms.len()), wildcard_row }; + let mut matrix = Matrix { rows: SmallVec::with_capacity(arms.len()), wildcard_row }; for (row_id, arm) in arms.iter().enumerate() { let v = MatrixRow { pats: PatStack::from_pattern(cx, arm.pat), @@ -809,7 +809,7 @@ impl<'p, 'tcx> Matrix<'p, 'tcx> { ctor: &Constructor<'tcx>, ) -> Matrix<'p, 'tcx> { let wildcard_row = self.wildcard_row.pop_head_constructor(pcx, ctor); - let rows = Vec::with_capacity(self.rows.len()); // Better waste capacity than reallocate a lot. + let rows = SmallVec::with_capacity(self.rows.len()); // Better waste capacity than reallocate a lot. let mut matrix = Matrix { rows, wildcard_row }; for (i, row) in self.rows().enumerate() { if ctor.is_covered_by(pcx, row.head().ctor()) {