A for loop is a lot faster apparently
This commit is contained in:
parent
ff90c6353b
commit
87a0a25b38
1 changed files with 9 additions and 29 deletions
|
@ -301,7 +301,7 @@ use rustc_span::Span;
|
||||||
|
|
||||||
use smallvec::{smallvec, SmallVec};
|
use smallvec::{smallvec, SmallVec};
|
||||||
use std::fmt;
|
use std::fmt;
|
||||||
use std::iter::{FromIterator, IntoIterator};
|
use std::iter::IntoIterator;
|
||||||
use std::lazy::OnceCell;
|
use std::lazy::OnceCell;
|
||||||
|
|
||||||
crate struct MatchCheckCtxt<'a, 'tcx> {
|
crate struct MatchCheckCtxt<'a, 'tcx> {
|
||||||
|
@ -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.
|
/// Pretty-printing for matrix row.
|
||||||
impl<'p, 'tcx> fmt::Debug for PatStack<'p, 'tcx> {
|
impl<'p, 'tcx> fmt::Debug for PatStack<'p, 'tcx> {
|
||||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||||
|
@ -565,11 +556,14 @@ impl<'p, 'tcx> Matrix<'p, 'tcx> {
|
||||||
ctor: &Constructor<'tcx>,
|
ctor: &Constructor<'tcx>,
|
||||||
ctor_wild_subpatterns: &Fields<'p, 'tcx>,
|
ctor_wild_subpatterns: &Fields<'p, 'tcx>,
|
||||||
) -> Matrix<'p, 'tcx> {
|
) -> Matrix<'p, 'tcx> {
|
||||||
self.patterns
|
let mut matrix = Matrix::empty();
|
||||||
.iter()
|
for row in &self.patterns {
|
||||||
.filter(|r| ctor.is_covered_by(pcx, r.head_ctor(pcx.cx)))
|
if ctor.is_covered_by(pcx, row.head_ctor(pcx.cx)) {
|
||||||
.map(|r| r.pop_head_constructor(ctor_wild_subpatterns))
|
let new_row = row.pop_head_constructor(ctor_wild_subpatterns);
|
||||||
.collect()
|
matrix.push(new_row);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
matrix
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -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
|
/// 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
|
/// 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
|
/// will always be either `Empty` (the whole pattern is unreachable) or `Full` (the whole pattern
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue