Skip to content

Commit

Permalink
Use SmallVec for Matrix
Browse files Browse the repository at this point in the history
  • Loading branch information
Nadrieril committed Dec 1, 2023
1 parent 98a9d5c commit eee8baf
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions compiler/rustc_mir_build/src/thir/pattern/usefulness.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<MatrixRow<'p, 'tcx>>,
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>,
Expand All @@ -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),
Expand Down Expand Up @@ -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()) {
Expand Down

0 comments on commit eee8baf

Please sign in to comment.