about summary refs log tree commit diff
path: root/compiler/rustc_passes/src/input_stats.rs
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2024-12-17 12:07:32 +0000
committerbors <bors@rust-lang.org>2024-12-17 12:07:32 +0000
commitf23a80a4c2fbca593b64e70f5970368824b4c5e9 (patch)
treefb6111f5c9f9064163fc6d3c6afcd5f158dc2f58 /compiler/rustc_passes/src/input_stats.rs
parent604d6691d9ee5c88a05569dd3f707b20afd76e97 (diff)
parentcdd71c9f3d6c08cd35edddf56800aa1aacbdaedc (diff)
downloadrust-f23a80a4c2fbca593b64e70f5970368824b4c5e9.tar.gz
rust-f23a80a4c2fbca593b64e70f5970368824b4c5e9.zip
Auto merge of #134414 - jhpratt:rollup-4gtfd1h, r=jhpratt
Rollup of 10 pull requests

Successful merges:

 - #134202 (Remove `rustc::existing_doc_keyword` lint)
 - #134354 (Handle fndef rendering together with signature rendering)
 - #134365 (Rename `rustc_mir_build::build` to `builder`)
 - #134368 (Use links to edition guide for edition migrations)
 - #134397 (rustc_borrowck: Suggest changing `&raw const` to `&raw mut` if applicable)
 - #134398 (AIX: add alignment info for test)
 - #134400 (Fix some comments related to upvars handling)
 - #134406 (Fix `-Z input-stats` ordering)
 - #134409 (bootstrap: fix a comment)
 - #134412 (small borrowck cleanup)

r? `@ghost`
`@rustbot` modify labels: rollup
Diffstat (limited to 'compiler/rustc_passes/src/input_stats.rs')
-rw-r--r--compiler/rustc_passes/src/input_stats.rs18
1 files changed, 11 insertions, 7 deletions
diff --git a/compiler/rustc_passes/src/input_stats.rs b/compiler/rustc_passes/src/input_stats.rs
index a65e91d629f..f9cb8c9b927 100644
--- a/compiler/rustc_passes/src/input_stats.rs
+++ b/compiler/rustc_passes/src/input_stats.rs
@@ -22,6 +22,10 @@ impl NodeStats {
     fn new() -> NodeStats {
         NodeStats { count: 0, size: 0 }
     }
+
+    fn accum_size(&self) -> usize {
+        self.count * self.size
+    }
 }
 
 struct Node {
@@ -121,11 +125,9 @@ impl<'k> StatCollector<'k> {
         // We will soon sort, so the initial order does not matter.
         #[allow(rustc::potential_query_instability)]
         let mut nodes: Vec<_> = self.nodes.iter().collect();
-        nodes.sort_by_cached_key(|(label, node)| {
-            (node.stats.count * node.stats.size, label.to_owned())
-        });
+        nodes.sort_by_cached_key(|(label, node)| (node.stats.accum_size(), label.to_owned()));
 
-        let total_size = nodes.iter().map(|(_, node)| node.stats.count * node.stats.size).sum();
+        let total_size = nodes.iter().map(|(_, node)| node.stats.accum_size()).sum();
         let total_count = nodes.iter().map(|(_, node)| node.stats.count).sum();
 
         eprintln!("{prefix} {title}");
@@ -138,7 +140,7 @@ impl<'k> StatCollector<'k> {
         let percent = |m, n| (m * 100) as f64 / n as f64;
 
         for (label, node) in nodes {
-            let size = node.stats.count * node.stats.size;
+            let size = node.stats.accum_size();
             eprintln!(
                 "{} {:<18}{:>10} ({:4.1}%){:>14}{:>14}",
                 prefix,
@@ -152,10 +154,12 @@ impl<'k> StatCollector<'k> {
                 // We will soon sort, so the initial order does not matter.
                 #[allow(rustc::potential_query_instability)]
                 let mut subnodes: Vec<_> = node.subnodes.iter().collect();
-                subnodes.sort_by_key(|(_, subnode)| subnode.count * subnode.size);
+                subnodes.sort_by_cached_key(|(label, subnode)| {
+                    (subnode.accum_size(), label.to_owned())
+                });
 
                 for (label, subnode) in subnodes {
-                    let size = subnode.count * subnode.size;
+                    let size = subnode.accum_size();
                     eprintln!(
                         "{} - {:<18}{:>10} ({:4.1}%){:>14}",
                         prefix,