Skip to content

Commit 0bbc422

Browse files
Use std based dedup in projection
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.
1 parent bc072ed commit 0bbc422

File tree

1 file changed

+6
-15
lines changed

1 file changed

+6
-15
lines changed

src/librustc/traits/project.rs

+6-15
Original file line numberDiff line numberDiff line change
@@ -824,21 +824,12 @@ fn project_type<'cx, 'gcx, 'tcx>(
824824
// Drop duplicates.
825825
//
826826
// Note: `candidates.vec` seems to be on the critical path of the
827-
// compiler. Replacing it with an hash set was also tried, which would
828-
// render the following dedup unnecessary. It led to cleaner code but
829-
// prolonged compiling time of `librustc` from 5m30s to 6m in one test, or
830-
// ~9% performance lost.
831-
if candidates.vec.len() > 1 {
832-
let mut i = 0;
833-
while i < candidates.vec.len() {
834-
let has_dup = (0..i).any(|j| candidates.vec[i] == candidates.vec[j]);
835-
if has_dup {
836-
candidates.vec.swap_remove(i);
837-
} else {
838-
i += 1;
839-
}
840-
}
841-
}
827+
// compiler. Replacing it with an HashSet was also tried, which would
828+
// render the following dedup unnecessary. The original comment indicated
829+
// that it was 9% slower, but that data is now obsolete and a new
830+
// benchmark should be performed.
831+
candidates.vec.sort_unstable();
832+
candidates.vec.dedup();
842833

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

0 commit comments

Comments
 (0)