diff options
| author | kennytm <kennytm@gmail.com> | 2018-12-01 01:05:48 +0800 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2018-12-01 01:05:48 +0800 |
| commit | b8198da4d2a9e643a9863bf4cddd82d01ebc3f71 (patch) | |
| tree | b916e01b11813d6477161904f5f9382c61ca1023 /src | |
| parent | d48ab693d1ce99f30c0cf9abdf45c209824fe825 (diff) | |
| parent | d4a6e739f3322c56e66fa8fef31569b7f16bc325 (diff) | |
| download | rust-b8198da4d2a9e643a9863bf4cddd82d01ebc3f71.tar.gz rust-b8198da4d2a9e643a9863bf4cddd82d01ebc3f71.zip | |
Rollup merge of #55821 - ljedrz:cached_key_sorts, r=michaelwoerister
Use sort_by_cached_key when the key function is not trivial/free I'm not 100% sure about `def_path_hash` (everything it does is inlined) but it seems like a good idea at least for the rest, as they are cloning.
Diffstat (limited to 'src')
| -rw-r--r-- | src/librustc/middle/resolve_lifetime.rs | 2 | ||||
| -rw-r--r-- | src/librustc/traits/object_safety.rs | 2 | ||||
| -rw-r--r-- | src/librustc_mir/monomorphize/partitioning.rs | 2 |
3 files changed, 3 insertions, 3 deletions
diff --git a/src/librustc/middle/resolve_lifetime.rs b/src/librustc/middle/resolve_lifetime.rs index 6ff450508d1..07054ee99af 100644 --- a/src/librustc/middle/resolve_lifetime.rs +++ b/src/librustc/middle/resolve_lifetime.rs @@ -1573,7 +1573,7 @@ impl<'a, 'tcx> LifetimeContext<'a, 'tcx> { .collect(); // ensure that we issue lints in a repeatable order - def_ids.sort_by_key(|&def_id| self.tcx.def_path_hash(def_id)); + def_ids.sort_by_cached_key(|&def_id| self.tcx.def_path_hash(def_id)); for def_id in def_ids { debug!( diff --git a/src/librustc/traits/object_safety.rs b/src/librustc/traits/object_safety.rs index c79fa386123..2909daf22b3 100644 --- a/src/librustc/traits/object_safety.rs +++ b/src/librustc/traits/object_safety.rs @@ -409,7 +409,7 @@ impl<'a, 'tcx> TyCtxt<'a, 'tcx, 'tcx> { .collect::<Vec<_>>(); // existential predicates need to be in a specific order - associated_types.sort_by_key(|item| self.def_path_hash(item.def_id)); + associated_types.sort_by_cached_key(|item| self.def_path_hash(item.def_id)); let projection_predicates = associated_types.into_iter().map(|item| { ty::ExistentialPredicate::Projection(ty::ExistentialProjection { diff --git a/src/librustc_mir/monomorphize/partitioning.rs b/src/librustc_mir/monomorphize/partitioning.rs index 6dba020120f..3a6ee6da422 100644 --- a/src/librustc_mir/monomorphize/partitioning.rs +++ b/src/librustc_mir/monomorphize/partitioning.rs @@ -985,7 +985,7 @@ fn collect_and_partition_mono_items<'a, 'tcx>( output.push_str(" @@"); let mut empty = Vec::new(); let cgus = item_to_cgus.get_mut(i).unwrap_or(&mut empty); - cgus.as_mut_slice().sort_by_key(|&(ref name, _)| name.clone()); + cgus.as_mut_slice().sort_by_cached_key(|&(ref name, _)| name.clone()); cgus.dedup(); for &(ref cgu_name, (linkage, _)) in cgus.iter() { output.push_str(" "); |
