Convert sort_by_key to sort_by_cached_key

This commit is contained in:
varkor 2018-03-30 10:23:27 +01:00
parent 4b9b70c394
commit eacfb330e6
9 changed files with 13 additions and 6 deletions

View File

@ -61,6 +61,7 @@
#![feature(refcell_replace_swap)]
#![feature(rustc_diagnostic_macros)]
#![feature(slice_patterns)]
#![feature(slice_sort_by_cached_key)]
#![feature(specialization)]
#![feature(unboxed_closures)]
#![feature(trace_macros)]

View File

@ -401,7 +401,7 @@ pub fn used_crates(tcx: TyCtxt, prefer: LinkagePreference)
.collect::<Vec<_>>();
let mut ordering = tcx.postorder_cnums(LOCAL_CRATE);
Lrc::make_mut(&mut ordering).reverse();
libs.sort_by_key(|&(a, _)| {
libs.sort_by_cached_key(|&(a, _)| {
ordering.iter().position(|x| *x == a)
});
libs

View File

@ -17,6 +17,7 @@ Rust MIR: a lowered representation of Rust. Also: an experiment!
#![deny(warnings)]
#![feature(slice_patterns)]
#![feature(slice_sort_by_cached_key)]
#![feature(from_ref)]
#![feature(box_patterns)]
#![feature(box_syntax)]

View File

@ -509,7 +509,7 @@ fn merge_codegen_units<'tcx>(initial_partitioning: &mut PreInliningPartitioning<
// Merge the two smallest codegen units until the target size is reached.
while codegen_units.len() > target_cgu_count {
// Sort small cgus to the back
codegen_units.sort_by_key(|cgu| usize::MAX - cgu.size_estimate());
codegen_units.sort_by_cached_key(|cgu| usize::MAX - cgu.size_estimate());
let mut smallest = codegen_units.pop().unwrap();
let second_smallest = codegen_units.last_mut().unwrap();

View File

@ -14,6 +14,7 @@
#![deny(warnings)]
#![feature(rustc_diagnostic_macros)]
#![feature(slice_sort_by_cached_key)]
#[macro_use]
extern crate log;
@ -3341,7 +3342,9 @@ impl<'a> Resolver<'a> {
let is_mod = |def| match def { Def::Mod(..) => true, _ => false };
let mut candidates =
self.lookup_import_candidates(name, TypeNS, is_mod);
candidates.sort_by_key(|c| (c.path.segments.len(), c.path.to_string()));
candidates.sort_by_cached_key(|c| {
(c.path.segments.len(), c.path.to_string())
});
if let Some(candidate) = candidates.get(0) {
format!("Did you mean `{}`?", candidate.path)
} else {
@ -3579,7 +3582,7 @@ impl<'a> Resolver<'a> {
let name = path[path.len() - 1].name;
// Make sure error reporting is deterministic.
names.sort_by_key(|name| name.as_str());
names.sort_by_cached_key(|name| name.as_str());
match find_best_match_for_name(names.iter(), &name.as_str(), None) {
Some(found) if found != name => Some(found),
_ => None,

View File

@ -830,7 +830,7 @@ pub fn trans_crate<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
// a bit more efficiently.
let codegen_units = {
let mut codegen_units = codegen_units;
codegen_units.sort_by_key(|cgu| usize::MAX - cgu.size_estimate());
codegen_units.sort_by_cached_key(|cgu| usize::MAX - cgu.size_estimate());
codegen_units
};

View File

@ -27,6 +27,7 @@
#![feature(libc)]
#![feature(quote)]
#![feature(rustc_diagnostic_macros)]
#![feature(slice_sort_by_cached_key)]
#![feature(optin_builtin_traits)]
#![feature(inclusive_range_fields)]
#![feature(underscore_lifetimes)]

View File

@ -799,7 +799,7 @@ impl<'a, 'gcx, 'tcx> ProbeContext<'a, 'gcx, 'tcx> {
.collect();
// sort them by the name so we have a stable result
names.sort_by_key(|n| n.as_str());
names.sort_by_cached_key(|n| n.as_str());
names
}

View File

@ -82,6 +82,7 @@ This API is completely unstable and subject to change.
#![feature(refcell_replace_swap)]
#![feature(rustc_diagnostic_macros)]
#![feature(slice_patterns)]
#![feature(slice_sort_by_cached_key)]
#![feature(dyn_trait)]
#[macro_use] extern crate log;