Skip to content

Commit eacfb33

Browse files
committed
Convert sort_by_key to sort_by_cached_key
1 parent 4b9b70c commit eacfb33

File tree

9 files changed

+13
-6
lines changed

9 files changed

+13
-6
lines changed

src/librustc/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@
6161
#![feature(refcell_replace_swap)]
6262
#![feature(rustc_diagnostic_macros)]
6363
#![feature(slice_patterns)]
64+
#![feature(slice_sort_by_cached_key)]
6465
#![feature(specialization)]
6566
#![feature(unboxed_closures)]
6667
#![feature(trace_macros)]

src/librustc/middle/cstore.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -401,7 +401,7 @@ pub fn used_crates(tcx: TyCtxt, prefer: LinkagePreference)
401401
.collect::<Vec<_>>();
402402
let mut ordering = tcx.postorder_cnums(LOCAL_CRATE);
403403
Lrc::make_mut(&mut ordering).reverse();
404-
libs.sort_by_key(|&(a, _)| {
404+
libs.sort_by_cached_key(|&(a, _)| {
405405
ordering.iter().position(|x| *x == a)
406406
});
407407
libs

src/librustc_mir/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ Rust MIR: a lowered representation of Rust. Also: an experiment!
1717
#![deny(warnings)]
1818

1919
#![feature(slice_patterns)]
20+
#![feature(slice_sort_by_cached_key)]
2021
#![feature(from_ref)]
2122
#![feature(box_patterns)]
2223
#![feature(box_syntax)]

src/librustc_mir/monomorphize/partitioning.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -509,7 +509,7 @@ fn merge_codegen_units<'tcx>(initial_partitioning: &mut PreInliningPartitioning<
509509
// Merge the two smallest codegen units until the target size is reached.
510510
while codegen_units.len() > target_cgu_count {
511511
// Sort small cgus to the back
512-
codegen_units.sort_by_key(|cgu| usize::MAX - cgu.size_estimate());
512+
codegen_units.sort_by_cached_key(|cgu| usize::MAX - cgu.size_estimate());
513513
let mut smallest = codegen_units.pop().unwrap();
514514
let second_smallest = codegen_units.last_mut().unwrap();
515515

src/librustc_resolve/lib.rs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
#![deny(warnings)]
1515

1616
#![feature(rustc_diagnostic_macros)]
17+
#![feature(slice_sort_by_cached_key)]
1718

1819
#[macro_use]
1920
extern crate log;
@@ -3341,7 +3342,9 @@ impl<'a> Resolver<'a> {
33413342
let is_mod = |def| match def { Def::Mod(..) => true, _ => false };
33423343
let mut candidates =
33433344
self.lookup_import_candidates(name, TypeNS, is_mod);
3344-
candidates.sort_by_key(|c| (c.path.segments.len(), c.path.to_string()));
3345+
candidates.sort_by_cached_key(|c| {
3346+
(c.path.segments.len(), c.path.to_string())
3347+
});
33453348
if let Some(candidate) = candidates.get(0) {
33463349
format!("Did you mean `{}`?", candidate.path)
33473350
} else {
@@ -3579,7 +3582,7 @@ impl<'a> Resolver<'a> {
35793582

35803583
let name = path[path.len() - 1].name;
35813584
// Make sure error reporting is deterministic.
3582-
names.sort_by_key(|name| name.as_str());
3585+
names.sort_by_cached_key(|name| name.as_str());
35833586
match find_best_match_for_name(names.iter(), &name.as_str(), None) {
35843587
Some(found) if found != name => Some(found),
35853588
_ => None,

src/librustc_trans/base.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -830,7 +830,7 @@ pub fn trans_crate<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
830830
// a bit more efficiently.
831831
let codegen_units = {
832832
let mut codegen_units = codegen_units;
833-
codegen_units.sort_by_key(|cgu| usize::MAX - cgu.size_estimate());
833+
codegen_units.sort_by_cached_key(|cgu| usize::MAX - cgu.size_estimate());
834834
codegen_units
835835
};
836836

src/librustc_trans/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
#![feature(libc)]
2828
#![feature(quote)]
2929
#![feature(rustc_diagnostic_macros)]
30+
#![feature(slice_sort_by_cached_key)]
3031
#![feature(optin_builtin_traits)]
3132
#![feature(inclusive_range_fields)]
3233
#![feature(underscore_lifetimes)]

src/librustc_typeck/check/method/probe.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -799,7 +799,7 @@ impl<'a, 'gcx, 'tcx> ProbeContext<'a, 'gcx, 'tcx> {
799799
.collect();
800800

801801
// sort them by the name so we have a stable result
802-
names.sort_by_key(|n| n.as_str());
802+
names.sort_by_cached_key(|n| n.as_str());
803803
names
804804
}
805805

src/librustc_typeck/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@ This API is completely unstable and subject to change.
8282
#![feature(refcell_replace_swap)]
8383
#![feature(rustc_diagnostic_macros)]
8484
#![feature(slice_patterns)]
85+
#![feature(slice_sort_by_cached_key)]
8586
#![feature(dyn_trait)]
8687

8788
#[macro_use] extern crate log;

0 commit comments

Comments
 (0)