about summary refs log tree commit diff
diff options
context:
space:
mode:
authorBjörn Steinbrink <bsteinbr@gmail.com>2019-01-15 21:53:37 +0100
committerBjörn Steinbrink <bsteinbr@gmail.com>2019-01-17 15:26:43 +0100
commitf0d3df39cbe1a3afaaabddbc5764b4057c713dd5 (patch)
tree0482535c1592d9380dd00819fb48dee4d93e56c3
parent33e6df4b62237af312bf6e3f40a97f5bdc94949a (diff)
downloadrust-f0d3df39cbe1a3afaaabddbc5764b4057c713dd5.tar.gz
rust-f0d3df39cbe1a3afaaabddbc5764b4057c713dd5.zip
Use a faster early exit during region expansion
Turns out that the equality check for regions is rather expensive, and
the current early exit check works in such a way, that the comparison is
even done twice. As we only really care about the case of equal scopes,
we can perform a faster, more specialized check and move it up one
level, so we can eventually skip the additional full comparison as well.
-rw-r--r--src/librustc/infer/lexical_region_resolve/mod.rs14
1 files changed, 8 insertions, 6 deletions
diff --git a/src/librustc/infer/lexical_region_resolve/mod.rs b/src/librustc/infer/lexical_region_resolve/mod.rs
index 39ce8cc621b..24ead374031 100644
--- a/src/librustc/infer/lexical_region_resolve/mod.rs
+++ b/src/librustc/infer/lexical_region_resolve/mod.rs
@@ -236,6 +236,14 @@ impl<'cx, 'gcx, 'tcx> LexicalResolver<'cx, 'gcx, 'tcx> {
 
         match *b_data {
             VarValue::Value(cur_region) => {
+                // Identical scopes can show up quite often, if the fixed point
+                // iteration converges slowly, skip them
+                if let (ReScope(a_scope), ReScope(cur_scope)) = (a_region, cur_region) {
+                    if a_scope == cur_scope {
+                        return false;
+                    }
+                }
+
                 let mut lub = self.lub_concrete_regions(a_region, cur_region);
                 if lub == cur_region {
                     return false;
@@ -275,12 +283,6 @@ impl<'cx, 'gcx, 'tcx> LexicalResolver<'cx, 'gcx, 'tcx> {
     fn lub_concrete_regions(&self, a: Region<'tcx>, b: Region<'tcx>) -> Region<'tcx> {
         let tcx = self.tcx();
 
-        // Equal scopes can show up quite often, if the fixed point
-        // iteration converges slowly, skip them
-        if a == b {
-            return a;
-        }
-
         match (a, b) {
             (&ty::ReClosureBound(..), _)
             | (_, &ty::ReClosureBound(..))