about summary refs log tree commit diff
diff options
context:
space:
mode:
authorNiko Matsakis <niko@alum.mit.edu>2015-11-10 05:24:25 -0500
committerNiko Matsakis <niko@alum.mit.edu>2015-11-10 22:18:06 -0500
commit61884e5543a68e7b99e33fc40afef1515b1a216d (patch)
tree51c49ffd252082ae1437243f08003476b9e0d3c7
parent87358728a49034f34ec44c93306c396145d6e77d (diff)
downloadrust-61884e5543a68e7b99e33fc40afef1515b1a216d.tar.gz
rust-61884e5543a68e7b99e33fc40afef1515b1a216d.zip
Clone the candidates and match-pairs lazilly, instead of eagerly.
-rw-r--r--src/librustc_mir/build/matches/test.rs34
1 files changed, 17 insertions, 17 deletions
diff --git a/src/librustc_mir/build/matches/test.rs b/src/librustc_mir/build/matches/test.rs
index 70d70bade21..79c2cbf69c4 100644
--- a/src/librustc_mir/build/matches/test.rs
+++ b/src/librustc_mir/build/matches/test.rs
@@ -288,14 +288,15 @@ impl<'a,'tcx> Builder<'a,'tcx> {
                                             test_outcome: usize,
                                             candidate: &Candidate<'pat, 'tcx>)
                                             -> Option<Candidate<'pat, 'tcx>> {
-        let candidate = candidate.clone();
-        let match_pairs = candidate.match_pairs;
         let result = self.match_pairs_under_assumption(test_lvalue,
                                                        test_kind,
                                                        test_outcome,
-                                                       match_pairs);
+                                                       &candidate.match_pairs);
         match result {
-            Some(match_pairs) => Some(Candidate { match_pairs: match_pairs, ..candidate }),
+            Some(match_pairs) => Some(Candidate { match_pairs: match_pairs,
+                                                  bindings: candidate.bindings.clone(),
+                                                  guard: candidate.guard.clone(),
+                                                  arm_index: candidate.arm_index }),
             None => None,
         }
     }
@@ -306,21 +307,20 @@ impl<'a,'tcx> Builder<'a,'tcx> {
                                           test_lvalue: &Lvalue<'tcx>,
                                           test_kind: &TestKind<'tcx>,
                                           test_outcome: usize,
-                                          match_pairs: Vec<MatchPair<'pat, 'tcx>>)
+                                          match_pairs: &[MatchPair<'pat, 'tcx>])
                                           -> Option<Vec<MatchPair<'pat, 'tcx>>> {
         let mut result = vec![];
 
         for match_pair in match_pairs {
-            // if the match pair is testing a different lvalue, it
-            // is unaffected by this test.
-            if match_pair.lvalue != *test_lvalue {
-                result.push(match_pair);
-                continue;
-            }
-
-            // if this test doesn't tell us anything about this match-pair, then hang onto it.
-            if !self.test_informs_match_pair(&match_pair, test_kind, test_outcome) {
-                result.push(match_pair);
+            // If the match pair is either:
+            // (1) testing a different lvalue; or,
+            // (2) the test doesn't tell us anything about this match-pair,
+            // then we have to retain it as for after the test is complete.
+            if
+                match_pair.lvalue != *test_lvalue || // (1)
+                !self.test_informs_match_pair(match_pair, test_kind, test_outcome) // (2)
+            {
+                result.push(match_pair.clone());
                 continue;
             }
 
@@ -445,7 +445,7 @@ impl<'a,'tcx> Builder<'a,'tcx> {
     /// observed that `option` has the discriminant `Ok`, then the
     /// second arm cannot apply.
     pub fn consequent_match_pairs_under_assumption<'pat>(&mut self,
-                                                         match_pair: MatchPair<'pat, 'tcx>,
+                                                         match_pair: &MatchPair<'pat, 'tcx>,
                                                          test_kind: &TestKind<'tcx>,
                                                          test_outcome: usize)
                                                          -> Option<Vec<MatchPair<'pat, 'tcx>>> {
@@ -511,7 +511,7 @@ impl<'a,'tcx> Builder<'a,'tcx> {
             PatternKind::Binding { .. } |
             PatternKind::Leaf { .. } |
             PatternKind::Deref { .. } => {
-                self.error_simplifyable(&match_pair)
+                self.error_simplifyable(match_pair)
             }
         }
     }