Skip to content

Short-circuit DefIdForest::intersection() #57060

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Dec 22, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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