Skip to content

Commit

Permalink
A for loop is a lot faster apparently
Browse files Browse the repository at this point in the history
  • Loading branch information
Nadrieril committed Sep 25, 2021
1 parent ff90c63 commit 87a0a25
Showing 1 changed file with 9 additions and 29 deletions.
38 changes: 9 additions & 29 deletions compiler/rustc_mir_build/src/thir/pattern/usefulness.rs
Expand Up @@ -301,7 +301,7 @@ use rustc_span::Span;

use smallvec::{smallvec, SmallVec};
use std::fmt;
use std::iter::{FromIterator, IntoIterator};
use std::iter::IntoIterator;
use std::lazy::OnceCell;

crate struct MatchCheckCtxt<'a, 'tcx> {
Expand Down Expand Up @@ -489,15 +489,6 @@ impl<'p, 'tcx> PartialEq for PatStack<'p, 'tcx> {
}
}

impl<'p, 'tcx> FromIterator<&'p Pat<'tcx>> for PatStack<'p, 'tcx> {
fn from_iter<T>(iter: T) -> Self
where
T: IntoIterator<Item = &'p Pat<'tcx>>,
{
Self::from_vec(iter.into_iter().collect())
}
}

/// Pretty-printing for matrix row.
impl<'p, 'tcx> fmt::Debug for PatStack<'p, 'tcx> {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
Expand Down Expand Up @@ -565,11 +556,14 @@ impl<'p, 'tcx> Matrix<'p, 'tcx> {
ctor: &Constructor<'tcx>,
ctor_wild_subpatterns: &Fields<'p, 'tcx>,
) -> Matrix<'p, 'tcx> {
self.patterns
.iter()
.filter(|r| ctor.is_covered_by(pcx, r.head_ctor(pcx.cx)))
.map(|r| r.pop_head_constructor(ctor_wild_subpatterns))
.collect()
let mut matrix = Matrix::empty();
for row in &self.patterns {
if ctor.is_covered_by(pcx, row.head_ctor(pcx.cx)) {
let new_row = row.pop_head_constructor(ctor_wild_subpatterns);
matrix.push(new_row);
}
}
matrix
}
}

Expand Down Expand Up @@ -609,20 +603,6 @@ impl<'p, 'tcx> fmt::Debug for Matrix<'p, 'tcx> {
}
}

impl<'p, 'tcx> FromIterator<PatStack<'p, 'tcx>> for Matrix<'p, 'tcx> {
fn from_iter<T>(iter: T) -> Self
where
T: IntoIterator<Item = PatStack<'p, 'tcx>>,
{
let mut matrix = Matrix::empty();
for x in iter {
// Using `push` ensures we correctly expand or-patterns.
matrix.push(x);
}
matrix
}
}

/// Given a pattern or a pattern-stack, this struct captures a set of its subpatterns. We use that
/// to track reachable sub-patterns arising from or-patterns. In the absence of or-patterns this
/// will always be either `Empty` (the whole pattern is unreachable) or `Full` (the whole pattern
Expand Down

0 comments on commit 87a0a25

Please sign in to comment.