Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 7e44cbf

Browse files
committedDec 17, 2024·
Factor out the common count * size pattern.
1 parent d727f86 commit 7e44cbf

File tree

1 file changed

+9
-8
lines changed

1 file changed

+9
-8
lines changed
 

‎compiler/rustc_passes/src/input_stats.rs

+9-8
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,10 @@ impl NodeStats {
2222
fn new() -> NodeStats {
2323
NodeStats { count: 0, size: 0 }
2424
}
25+
26+
fn nodes_size(&self) -> usize {
27+
self.count * self.size
28+
}
2529
}
2630

2731
struct Node {
@@ -121,11 +125,9 @@ impl<'k> StatCollector<'k> {
121125
// We will soon sort, so the initial order does not matter.
122126
#[allow(rustc::potential_query_instability)]
123127
let mut nodes: Vec<_> = self.nodes.iter().collect();
124-
nodes.sort_by_cached_key(|(label, node)| {
125-
(node.stats.count * node.stats.size, label.to_owned())
126-
});
128+
nodes.sort_by_cached_key(|(label, node)| (node.stats.nodes_size(), label.to_owned()));
127129

128-
let total_size = nodes.iter().map(|(_, node)| node.stats.count * node.stats.size).sum();
130+
let total_size = nodes.iter().map(|(_, node)| node.stats.nodes_size()).sum();
129131
let total_count = nodes.iter().map(|(_, node)| node.stats.count).sum();
130132

131133
eprintln!("{prefix} {title}");
@@ -138,7 +140,7 @@ impl<'k> StatCollector<'k> {
138140
let percent = |m, n| (m * 100) as f64 / n as f64;
139141

140142
for (label, node) in nodes {
141-
let size = node.stats.count * node.stats.size;
143+
let size = node.stats.nodes_size();
142144
eprintln!(
143145
"{} {:<18}{:>10} ({:4.1}%){:>14}{:>14}",
144146
prefix,
@@ -153,12 +155,11 @@ impl<'k> StatCollector<'k> {
153155
#[allow(rustc::potential_query_instability)]
154156
let mut subnodes: Vec<_> = node.subnodes.iter().collect();
155157
subnodes.sort_by(|(label1, subnode1), (label2, subnode2)| {
156-
(subnode1.count * subnode1.size, label1)
157-
.cmp(&(subnode2.count * subnode2.size, label2))
158+
(subnode1.nodes_size(), label1).cmp(&(subnode2.nodes_size(), label2))
158159
});
159160

160161
for (label, subnode) in subnodes {
161-
let size = subnode.count * subnode.size;
162+
let size = subnode.nodes_size();
162163
eprintln!(
163164
"{} - {:<18}{:>10} ({:4.1}%){:>14}",
164165
prefix,

0 commit comments

Comments
 (0)
Please sign in to comment.