Skip to content

Commit 1649c2e

Browse files
committed
Use sort_by_cached_key when key the function is not trivial/free
1 parent 36a50c2 commit 1649c2e

File tree

4 files changed

+5
-5
lines changed

4 files changed

+5
-5
lines changed

src/librustc/middle/resolve_lifetime.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1573,7 +1573,7 @@ impl<'a, 'tcx> LifetimeContext<'a, 'tcx> {
15731573
.collect();
15741574

15751575
// ensure that we issue lints in a repeatable order
1576-
def_ids.sort_by_key(|&def_id| self.tcx.def_path_hash(def_id));
1576+
def_ids.sort_by_cached_key(|&def_id| self.tcx.def_path_hash(def_id));
15771577

15781578
for def_id in def_ids {
15791579
debug!(

src/librustc/traits/object_safety.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -408,7 +408,7 @@ impl<'a, 'tcx> TyCtxt<'a, 'tcx, 'tcx> {
408408
.collect::<Vec<_>>();
409409

410410
// existential predicates need to be in a specific order
411-
associated_types.sort_by_key(|item| self.def_path_hash(item.def_id));
411+
associated_types.sort_by_cached_key(|item| self.def_path_hash(item.def_id));
412412

413413
let projection_predicates = associated_types.into_iter().map(|item| {
414414
ty::ExistentialPredicate::Projection(ty::ExistentialProjection {

src/librustc_mir/borrow_check/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -341,7 +341,7 @@ fn do_mir_borrowck<'a, 'gcx, 'tcx>(
341341
}
342342

343343
if !mbcx.errors_buffer.is_empty() {
344-
mbcx.errors_buffer.sort_by_key(|diag| diag.span.primary_span());
344+
mbcx.errors_buffer.sort_by_cached_key(|diag| diag.span.primary_span());
345345

346346
if tcx.migrate_borrowck() {
347347
// When borrowck=migrate, check if AST-borrowck would

src/librustc_mir/monomorphize/partitioning.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -585,7 +585,7 @@ fn merge_codegen_units<'tcx>(tcx: TyCtxt<'_, 'tcx, 'tcx>,
585585
// smallest into each other) we're sure to start off with a deterministic
586586
// order (sorted by name). This'll mean that if two cgus have the same size
587587
// the stable sort below will keep everything nice and deterministic.
588-
codegen_units.sort_by_key(|cgu| cgu.name().clone());
588+
codegen_units.sort_by_cached_key(|cgu| cgu.name().clone());
589589

590590
// Merge the two smallest codegen units until the target size is reached.
591591
while codegen_units.len() > target_cgu_count {
@@ -985,7 +985,7 @@ fn collect_and_partition_mono_items<'a, 'tcx>(
985985
output.push_str(" @@");
986986
let mut empty = Vec::new();
987987
let cgus = item_to_cgus.get_mut(i).unwrap_or(&mut empty);
988-
cgus.as_mut_slice().sort_by_key(|&(ref name, _)| name.clone());
988+
cgus.as_mut_slice().sort_by_cached_key(|&(ref name, _)| name.clone());
989989
cgus.dedup();
990990
for &(ref cgu_name, (linkage, _)) in cgus.iter() {
991991
output.push_str(" ");

0 commit comments

Comments
 (0)