Skip to content

Commit c25e13a

Browse files
shuaKobzol
authored andcommitted
PR: 'diff' subcommand, no-mut
1 parent 5139985 commit c25e13a

File tree

1 file changed

+15
-5
lines changed

1 file changed

+15
-5
lines changed

summarize/src/main.rs

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -120,14 +120,25 @@ fn diff(opt: DiffOpt) -> Result<(), Box<dyn Error + Send + Sync>> {
120120
"Incremental hashing time",
121121
));
122122

123+
let label_max_width = (results.query_data.iter())
124+
.map(|q| q.label.len())
125+
.max()
126+
.unwrap_or(0);
127+
fn pad(s: &str, max: usize) -> String {
128+
let Some(pad) = max.checked_sub(s.len()) else {
129+
return s.to_string();
130+
};
131+
132+
format!("{s}{:.<pad$}", " ")
133+
}
123134
for query_data in results.query_data {
124135
let exclude = opt.exclude.iter().any(|e| query_data.label.contains(e));
125136
if exclude {
126137
continue;
127138
}
128139

129140
table.add_row(row![
130-
query_data.label,
141+
pad(&query_data.label, label_max_width),
131142
format!("{:.2?}", query_data.self_time),
132143
format!("{:+.2}%", query_data.self_time_change),
133144
format!("{:.2?}", query_data.time),
@@ -250,16 +261,15 @@ fn summarize(opt: SummarizeOpt) -> Result<(), Box<dyn Error + Send + Sync>> {
250261
let total_time = results.total_time.as_nanos() as f64;
251262
let mut percent_total_time: f64 = 0.0;
252263

253-
let mut label_max_width = (results.query_data.iter())
264+
let label_max_width = (results.query_data.iter())
254265
.map(|q| q.label.len())
255266
.max()
256267
.unwrap_or(0);
257268
fn pad(s: &str, max: usize) -> String {
258-
if s.len() >= max {
269+
let Some(pad) = max.checked_sub(s.len()) else {
259270
return s.to_string();
260-
}
271+
};
261272

262-
let pad = max.saturating_sub(s.len());
263273
format!("{s}{:.<pad$}", " ")
264274
}
265275
for query_data in results.query_data {

0 commit comments

Comments
 (0)