Skip to content

Commit c291b8a

Browse files
committed
clean up add_stats function
1 parent da5b805 commit c291b8a

File tree

1 file changed

+24
-14
lines changed

1 file changed

+24
-14
lines changed

analyze/analyses/monos/mod.rs

Lines changed: 24 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -133,27 +133,37 @@ fn process_monomorphizations(monos_map: MonosMap, opts: &opt::Monos) -> Vec<Mono
133133
fn add_stats(mut monos: Vec<MonosEntry>, opts: &opt::Monos) -> Vec<MonosEntry> {
134134
let max_generics = opts.max_generics() as usize;
135135

136-
// Create an entry to represent the remaining rows that will be truncated.
137-
let (rem_cnt, rem_size, rem_savings) = summarize_entries(monos.iter().skip(max_generics));
138-
let remaining = MonosEntry {
139-
name: format!("... and {} more.", rem_cnt),
140-
size: rem_size,
141-
insts: vec![],
142-
bloat: rem_savings,
136+
// Create an entry to represent the remaining rows that will be truncated,
137+
// only if there are more generics than we will display.
138+
let remaining: Option<MonosEntry> = {
139+
if monos.len() > max_generics {
140+
let (rem_cnt, rem_size, rem_savings) =
141+
summarize_entries(monos.iter().skip(max_generics));
142+
Some(MonosEntry {
143+
name: format!("... and {} more.", rem_cnt),
144+
size: rem_size,
145+
insts: vec![],
146+
bloat: rem_savings,
147+
})
148+
} else {
149+
None
150+
}
143151
};
144152

145153
// Create an entry to represent the 'total' summary.
146-
let (total_cnt, total_size, total_savings) = summarize_entries(monos.iter());
147-
let total = MonosEntry {
148-
name: format!("Σ [{} Total Rows]", total_cnt),
149-
size: total_size,
150-
insts: vec![],
151-
bloat: total_savings,
154+
let total = {
155+
let (total_cnt, total_size, total_savings) = summarize_entries(monos.iter());
156+
MonosEntry {
157+
name: format!("Σ [{} Total Rows]", total_cnt),
158+
size: total_size,
159+
insts: vec![],
160+
bloat: total_savings,
161+
}
152162
};
153163

154164
// Truncate the vector, and add the 'remaining' and 'total' summary entries.
155165
monos.truncate(max_generics);
156-
if rem_cnt > 0 {
166+
if let Some(remaining) = remaining {
157167
monos.push(remaining);
158168
}
159169
monos.push(total);

0 commit comments

Comments
 (0)