From 775bacd1b8d97ade32c8d74ce35be1f34759aead Mon Sep 17 00:00:00 2001 From: Maybe Waffle Date: Tue, 7 Mar 2023 17:43:42 +0000 Subject: Simplify `sort_by` calls --- compiler/rustc_session/src/code_stats.rs | 12 +++--------- 1 file changed, 3 insertions(+), 9 deletions(-) (limited to 'compiler/rustc_session/src') diff --git a/compiler/rustc_session/src/code_stats.rs b/compiler/rustc_session/src/code_stats.rs index 55178250472..0dfee92f404 100644 --- a/compiler/rustc_session/src/code_stats.rs +++ b/compiler/rustc_session/src/code_stats.rs @@ -2,7 +2,7 @@ use rustc_data_structures::fx::FxHashSet; use rustc_data_structures::sync::Lock; use rustc_span::Symbol; use rustc_target::abi::{Align, Size}; -use std::cmp::{self, Ordering}; +use std::cmp; #[derive(Clone, PartialEq, Eq, Hash, Debug)] pub struct VariantInfo { @@ -87,7 +87,7 @@ impl CodeStats { // Except for Generators, whose variants are already sorted according to // their yield points in `variant_info_for_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 { kind, @@ -107,13 +107,7 @@ impl CodeStats { // Primary sort: large-to-small. // Secondary sort: description (dictionary order) - sorted.sort_by(|info1, info2| { - // (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, - } - }); + sorted.sort_by_key(|info| (cmp::Reverse(info.overall_size), &info.type_description)); for info in sorted { let TypeSizeInfo { type_description, overall_size, align, kind, variants, .. } = info; -- cgit 1.4.1-3-g733a5