Convert sort_unstable_by_key to sort_by_cached_key

This commit is contained in:
varkor 2018-03-30 10:40:25 +01:00
parent eacfb330e6
commit d3fe534fcf
3 changed files with 6 additions and 9 deletions

View file

@ -1414,7 +1414,7 @@ impl<'a, 'b: 'a, 'tcx: 'b> IsolatedEncoder<'a, 'b, 'tcx> {
let mut all_impls: Vec<_> = visitor.impls.into_iter().collect();
// Bring everything into deterministic order for hashing
all_impls.sort_unstable_by_key(|&(trait_def_id, _)| {
all_impls.sort_by_cached_key(|&(trait_def_id, _)| {
tcx.def_path_hash(trait_def_id)
});
@ -1422,7 +1422,7 @@ impl<'a, 'b: 'a, 'tcx: 'b> IsolatedEncoder<'a, 'b, 'tcx> {
.into_iter()
.map(|(trait_def_id, mut impls)| {
// Bring everything into deterministic order for hashing
impls.sort_unstable_by_key(|&def_index| {
impls.sort_by_cached_key(|&def_index| {
tcx.hir.definitions().def_path_hash(def_index)
});

View file

@ -21,6 +21,7 @@
#![feature(macro_lifetime_matcher)]
#![feature(quote)]
#![feature(rustc_diagnostic_macros)]
#![feature(slice_sort_by_cached_key)]
#![feature(specialization)]
#![feature(rustc_private)]

View file

@ -1151,13 +1151,9 @@ impl<'a> ModuleData<'a> {
fn for_each_child_stable<F: FnMut(Ident, Namespace, &'a NameBinding<'a>)>(&self, mut f: F) {
let resolutions = self.resolutions.borrow();
let mut resolutions = resolutions.iter().map(|(&(ident, ns), &resolution)| {
// Pre-compute keys for sorting
(ident.name.as_str(), ns, ident, resolution)
})
.collect::<Vec<_>>();
resolutions.sort_unstable_by_key(|&(str, ns, ..)| (str, ns));
for &(_, ns, ident, resolution) in resolutions.iter() {
let mut resolutions = resolutions.iter().collect::<Vec<_>>();
resolutions.sort_by_cached_key(|&(&(ident, ns), _)| (ident.name.as_str(), ns));
for &(&(ident, ns), &resolution) in resolutions.iter() {
resolution.borrow().binding.map(|binding| f(ident, ns, binding));
}
}