Simplify sort_by
calls
This commit is contained in:
parent
ac4379fea9
commit
775bacd1b8
7 changed files with 10 additions and 16 deletions
|
@ -1031,7 +1031,7 @@ impl<'a, 'tcx> ProbeContext<'a, 'tcx> {
|
||||||
.collect();
|
.collect();
|
||||||
|
|
||||||
// Sort them by the name so we have a stable result.
|
// Sort them by the name so we have a stable result.
|
||||||
names.sort_by(|a, b| a.as_str().partial_cmp(b.as_str()).unwrap());
|
names.sort_by(|a, b| a.as_str().cmp(b.as_str()));
|
||||||
names
|
names
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -42,7 +42,7 @@ use rustc_trait_selection::traits::{
|
||||||
use super::probe::{AutorefOrPtrAdjustment, IsSuggestion, Mode, ProbeScope};
|
use super::probe::{AutorefOrPtrAdjustment, IsSuggestion, Mode, ProbeScope};
|
||||||
use super::{CandidateSource, MethodError, NoMatchData};
|
use super::{CandidateSource, MethodError, NoMatchData};
|
||||||
use rustc_hir::intravisit::Visitor;
|
use rustc_hir::intravisit::Visitor;
|
||||||
use std::cmp::Ordering;
|
use std::cmp::{self, Ordering};
|
||||||
use std::iter;
|
use std::iter;
|
||||||
|
|
||||||
impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
||||||
|
@ -2517,7 +2517,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
||||||
|
|
||||||
if !candidates.is_empty() {
|
if !candidates.is_empty() {
|
||||||
// Sort from most relevant to least relevant.
|
// Sort from most relevant to least relevant.
|
||||||
candidates.sort_by(|a, b| a.cmp(b).reverse());
|
candidates.sort_by_key(|&info| cmp::Reverse(info));
|
||||||
candidates.dedup();
|
candidates.dedup();
|
||||||
|
|
||||||
let param_type = match rcvr_ty.kind() {
|
let param_type = match rcvr_ty.kind() {
|
||||||
|
|
|
@ -24,7 +24,7 @@ pub fn merge_codegen_units<'tcx>(
|
||||||
// smallest into each other) we're sure to start off with a deterministic
|
// smallest into each other) we're sure to start off with a deterministic
|
||||||
// order (sorted by name). This'll mean that if two cgus have the same size
|
// order (sorted by name). This'll mean that if two cgus have the same size
|
||||||
// the stable sort below will keep everything nice and deterministic.
|
// the stable sort below will keep everything nice and deterministic.
|
||||||
codegen_units.sort_by(|a, b| a.name().as_str().partial_cmp(b.name().as_str()).unwrap());
|
codegen_units.sort_by(|a, b| a.name().as_str().cmp(b.name().as_str()));
|
||||||
|
|
||||||
// This map keeps track of what got merged into what.
|
// This map keeps track of what got merged into what.
|
||||||
let mut cgu_contents: FxHashMap<Symbol, Vec<Symbol>> =
|
let mut cgu_contents: FxHashMap<Symbol, Vec<Symbol>> =
|
||||||
|
|
|
@ -252,7 +252,7 @@ pub fn partition<'tcx>(
|
||||||
internalization_candidates: _,
|
internalization_candidates: _,
|
||||||
} = post_inlining;
|
} = post_inlining;
|
||||||
|
|
||||||
result.sort_by(|a, b| a.name().as_str().partial_cmp(b.name().as_str()).unwrap());
|
result.sort_by(|a, b| a.name().as_str().cmp(b.name().as_str()));
|
||||||
|
|
||||||
result
|
result
|
||||||
}
|
}
|
||||||
|
|
|
@ -71,7 +71,7 @@ pub fn report_suspicious_mismatch_block(
|
||||||
.collect();
|
.collect();
|
||||||
|
|
||||||
// sort by `lo`, so the large block spans in the front
|
// sort by `lo`, so the large block spans in the front
|
||||||
matched_spans.sort_by(|a, b| a.0.lo().cmp(&b.0.lo()));
|
matched_spans.sort_by_key(|(span, _)| span.lo());
|
||||||
|
|
||||||
// We use larger block whose identation is well to cover those inner mismatched blocks
|
// We use larger block whose identation is well to cover those inner mismatched blocks
|
||||||
// O(N^2) here, but we are on error reporting path, so it is fine
|
// O(N^2) here, but we are on error reporting path, so it is fine
|
||||||
|
|
|
@ -1736,7 +1736,7 @@ impl<'a: 'ast, 'ast, 'tcx> LateResolutionVisitor<'a, '_, 'ast, 'tcx> {
|
||||||
|
|
||||||
let name = path[path.len() - 1].ident.name;
|
let name = path[path.len() - 1].ident.name;
|
||||||
// Make sure error reporting is deterministic.
|
// Make sure error reporting is deterministic.
|
||||||
names.sort_by(|a, b| a.candidate.as_str().partial_cmp(b.candidate.as_str()).unwrap());
|
names.sort_by(|a, b| a.candidate.as_str().cmp(b.candidate.as_str()));
|
||||||
|
|
||||||
match find_best_match_for_name(
|
match find_best_match_for_name(
|
||||||
&names.iter().map(|suggestion| suggestion.candidate).collect::<Vec<Symbol>>(),
|
&names.iter().map(|suggestion| suggestion.candidate).collect::<Vec<Symbol>>(),
|
||||||
|
|
|
@ -2,7 +2,7 @@ use rustc_data_structures::fx::FxHashSet;
|
||||||
use rustc_data_structures::sync::Lock;
|
use rustc_data_structures::sync::Lock;
|
||||||
use rustc_span::Symbol;
|
use rustc_span::Symbol;
|
||||||
use rustc_target::abi::{Align, Size};
|
use rustc_target::abi::{Align, Size};
|
||||||
use std::cmp::{self, Ordering};
|
use std::cmp;
|
||||||
|
|
||||||
#[derive(Clone, PartialEq, Eq, Hash, Debug)]
|
#[derive(Clone, PartialEq, Eq, Hash, Debug)]
|
||||||
pub struct VariantInfo {
|
pub struct VariantInfo {
|
||||||
|
@ -87,7 +87,7 @@ impl CodeStats {
|
||||||
// Except for Generators, whose variants are already sorted according to
|
// Except for Generators, whose variants are already sorted according to
|
||||||
// their yield points in `variant_info_for_generator`.
|
// their yield points in `variant_info_for_generator`.
|
||||||
if kind != DataTypeKind::Generator {
|
if kind != DataTypeKind::Generator {
|
||||||
variants.sort_by(|info1, info2| info2.size.cmp(&info1.size));
|
variants.sort_by_key(|info| cmp::Reverse(info.size));
|
||||||
}
|
}
|
||||||
let info = TypeSizeInfo {
|
let info = TypeSizeInfo {
|
||||||
kind,
|
kind,
|
||||||
|
@ -107,13 +107,7 @@ impl CodeStats {
|
||||||
|
|
||||||
// Primary sort: large-to-small.
|
// Primary sort: large-to-small.
|
||||||
// Secondary sort: description (dictionary order)
|
// Secondary sort: description (dictionary order)
|
||||||
sorted.sort_by(|info1, info2| {
|
sorted.sort_by_key(|info| (cmp::Reverse(info.overall_size), &info.type_description));
|
||||||
// (reversing cmp order to get large-to-small ordering)
|
|
||||||
match info2.overall_size.cmp(&info1.overall_size) {
|
|
||||||
Ordering::Equal => info1.type_description.cmp(&info2.type_description),
|
|
||||||
other => other,
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
for info in sorted {
|
for info in sorted {
|
||||||
let TypeSizeInfo { type_description, overall_size, align, kind, variants, .. } = info;
|
let TypeSizeInfo { type_description, overall_size, align, kind, variants, .. } = info;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue