]> git.lizzy.rs Git - rust.git/commitdiff
Clean up YieldFinder
authorJohn Kåre Alsaker <john.kare.alsaker@gmail.com>
Fri, 25 Aug 2017 18:10:23 +0000 (20:10 +0200)
committerJohn Kåre Alsaker <john.kare.alsaker@gmail.com>
Fri, 25 Aug 2017 18:10:23 +0000 (20:10 +0200)
src/librustc/middle/region.rs

index 6374eb3ff9060da6e44c48d51c6017a01ecb700a..944d03737d37d0eb48dfa595ca8b1d9178a76284 100644 (file)
@@ -1175,13 +1175,18 @@ struct YieldFinder<'a> {
 
 impl<'a> YieldFinder<'a> {
     fn lookup<F: FnOnce(&mut Self)>(&mut self, id: NodeId, f: F) {
-        if let Some(result) = self.cache.get(&id) {
-            self.result = *result;
+        // Don't traverse further if we found a yield expression
+        if self.result.is_some() {
             return;
         }
-        if self.result.is_some() {
+
+        // See if there's an entry in the cache
+        if let Some(result) = self.cache.get(&id) {
+            self.result = *result;
             return;
         }
+
+        // Otherwise calculate the result and insert it into the cache
         f(self);
         self.cache.insert(id, self.result);
     }