Skip to content

Commit

Permalink
Auto merge of #57060 - nikic:inhabit-perf-2, r=varkor
Browse files Browse the repository at this point in the history
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
  • Loading branch information
bors committed Dec 22, 2018
2 parents 9966590 + f93cbf6 commit fa922ab
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion src/librustc/ty/inhabitedness/def_id_forest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -74,10 +74,21 @@ impl<'a, 'gcx, 'tcx> DefIdForest {
iter: I) -> DefIdForest
where I: IntoIterator<Item=DefIdForest>
{
let mut ret = DefIdForest::full(tcx);
let mut iter = iter.into_iter();
let mut ret = if let Some(first) = iter.next() {
first
} else {
return DefIdForest::full(tcx);
};

let mut next_ret = SmallVec::new();
let mut old_ret: SmallVec<[DefId; 1]> = SmallVec::new();
for next_forest in iter {
// No need to continue if the intersection is already empty.
if ret.is_empty() {
break;
}

for id in ret.root_ids.drain() {
if next_forest.contains(tcx, id) {
next_ret.push(id);
Expand Down

0 comments on commit fa922ab

Please sign in to comment.