Skip to content

Commit fa922ab

Browse files
committed
Auto merge of #57060 - nikic:inhabit-perf-2, r=varkor
Short-circuit DefIdForest::intersection() If the forest is already empty, there is no point in intersecting further. Also handle the first element separately, so we don't compute an unnecessary intersection between the full forest and the first element, which is always equal to the first element. This is the second try at fixing #57028, as the previous attempt only recovered part of the regression. I checked locally that this drops time spent in ty::inhabitedness for syn-check a lot, though not to zero. r? @varkor
2 parents 9966590 + f93cbf6 commit fa922ab

File tree

1 file changed

+12
-1
lines changed

1 file changed

+12
-1
lines changed

src/librustc/ty/inhabitedness/def_id_forest.rs

+12-1
Original file line numberDiff line numberDiff line change
@@ -74,10 +74,21 @@ impl<'a, 'gcx, 'tcx> DefIdForest {
7474
iter: I) -> DefIdForest
7575
where I: IntoIterator<Item=DefIdForest>
7676
{
77-
let mut ret = DefIdForest::full(tcx);
77+
let mut iter = iter.into_iter();
78+
let mut ret = if let Some(first) = iter.next() {
79+
first
80+
} else {
81+
return DefIdForest::full(tcx);
82+
};
83+
7884
let mut next_ret = SmallVec::new();
7985
let mut old_ret: SmallVec<[DefId; 1]> = SmallVec::new();
8086
for next_forest in iter {
87+
// No need to continue if the intersection is already empty.
88+
if ret.is_empty() {
89+
break;
90+
}
91+
8192
for id in ret.root_ids.drain() {
8293
if next_forest.contains(tcx, id) {
8394
next_ret.push(id);

0 commit comments

Comments
 (0)