about summary refs log tree commit diff
path: root/compiler/rustc_session/src
diff options
context:
space:
mode:
authorMatthias Krüger <matthias.krueger@famsik.de>2023-03-08 21:24:51 +0100
committerGitHub <noreply@github.com>2023-03-08 21:24:51 +0100
commit1a9376dc47860ca4bbd21e2b5bb8fb64bba81af0 (patch)
treeffbf02e64f6bd13b015bc73b279072d6782dc1b1 /compiler/rustc_session/src
parent9b6b7a3e84f2f509149e00b6ad30c0b46e88f0a3 (diff)
parent775bacd1b8d97ade32c8d74ce35be1f34759aead (diff)
downloadrust-1a9376dc47860ca4bbd21e2b5bb8fb64bba81af0.tar.gz
rust-1a9376dc47860ca4bbd21e2b5bb8fb64bba81af0.zip
Rollup merge of #108873 - WaffleLapkin:cmp, r=cjgillot
Simplify `sort_by` calls

small cleanup
Diffstat (limited to 'compiler/rustc_session/src')
-rw-r--r--compiler/rustc_session/src/code_stats.rs12
1 files changed, 3 insertions, 9 deletions
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;