Skip to content

Commit f0d3df3

Browse files
committed
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.
1 parent 33e6df4 commit f0d3df3

File tree

1 file changed

+8
-6
lines changed
  • src/librustc/infer/lexical_region_resolve

1 file changed

+8
-6
lines changed

Diff for: src/librustc/infer/lexical_region_resolve/mod.rs

+8-6
Original file line numberDiff line numberDiff line change
@@ -236,6 +236,14 @@ impl<'cx, 'gcx, 'tcx> LexicalResolver<'cx, 'gcx, 'tcx> {
236236

237237
match *b_data {
238238
VarValue::Value(cur_region) => {
239+
// Identical scopes can show up quite often, if the fixed point
240+
// iteration converges slowly, skip them
241+
if let (ReScope(a_scope), ReScope(cur_scope)) = (a_region, cur_region) {
242+
if a_scope == cur_scope {
243+
return false;
244+
}
245+
}
246+
239247
let mut lub = self.lub_concrete_regions(a_region, cur_region);
240248
if lub == cur_region {
241249
return false;
@@ -275,12 +283,6 @@ impl<'cx, 'gcx, 'tcx> LexicalResolver<'cx, 'gcx, 'tcx> {
275283
fn lub_concrete_regions(&self, a: Region<'tcx>, b: Region<'tcx>) -> Region<'tcx> {
276284
let tcx = self.tcx();
277285

278-
// Equal scopes can show up quite often, if the fixed point
279-
// iteration converges slowly, skip them
280-
if a == b {
281-
return a;
282-
}
283-
284286
match (a, b) {
285287
(&ty::ReClosureBound(..), _)
286288
| (_, &ty::ReClosureBound(..))

0 commit comments

Comments
 (0)