Skip to content

Commit

Permalink
Use std based dedup in projection
Browse files Browse the repository at this point in the history
Unstable sort was added recently, and the code that is being modified is 3 years old. As quicksort doesn't allocate it will likely perform as well as, or better than linear search.
  • Loading branch information
ishitatsuyuki authored Jan 22, 2018
1 parent bc072ed commit 0bbc422
Showing 1 changed file with 6 additions and 15 deletions.
21 changes: 6 additions & 15 deletions src/librustc/traits/project.rs
Original file line number Diff line number Diff line change
Expand Up @@ -824,21 +824,12 @@ fn project_type<'cx, 'gcx, 'tcx>(
// Drop duplicates.
//
// Note: `candidates.vec` seems to be on the critical path of the
// compiler. Replacing it with an hash set was also tried, which would
// render the following dedup unnecessary. It led to cleaner code but
// prolonged compiling time of `librustc` from 5m30s to 6m in one test, or
// ~9% performance lost.
if candidates.vec.len() > 1 {
let mut i = 0;
while i < candidates.vec.len() {
let has_dup = (0..i).any(|j| candidates.vec[i] == candidates.vec[j]);
if has_dup {
candidates.vec.swap_remove(i);
} else {
i += 1;
}
}
}
// compiler. Replacing it with an HashSet was also tried, which would
// render the following dedup unnecessary. The original comment indicated
// that it was 9% slower, but that data is now obsolete and a new
// benchmark should be performed.
candidates.vec.sort_unstable();
candidates.vec.dedup();

// Prefer where-clauses. As in select, if there are multiple
// candidates, we prefer where-clause candidates over impls. This
Expand Down

0 comments on commit 0bbc422

Please sign in to comment.