about summary refs log tree commit diff
diff options
context:
space:
mode:
authorNadrieril <nadrieril+git@gmail.com>2021-09-23 00:36:49 +0100
committerNadrieril <nadrieril+git@gmail.com>2021-09-26 00:05:52 +0100
commit87a0a25b38cb791b5145dcba53ac83f8dc76f197 (patch)
tree5a5a2792e46c1fa2bb62d2ab6e01758dbae77020
parentff90c6353b1e78aee13acedbfd545b02bc9e830f (diff)
downloadrust-87a0a25b38cb791b5145dcba53ac83f8dc76f197.tar.gz
rust-87a0a25b38cb791b5145dcba53ac83f8dc76f197.zip
A for loop is a lot faster apparently
-rw-r--r--compiler/rustc_mir_build/src/thir/pattern/usefulness.rs38
1 files changed, 9 insertions, 29 deletions
diff --git a/compiler/rustc_mir_build/src/thir/pattern/usefulness.rs b/compiler/rustc_mir_build/src/thir/pattern/usefulness.rs
index 4824794d581..80e9bcbde77 100644
--- a/compiler/rustc_mir_build/src/thir/pattern/usefulness.rs
+++ b/compiler/rustc_mir_build/src/thir/pattern/usefulness.rs
@@ -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> {
@@ -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 {
@@ -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
     }
 }
 
@@ -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