From 6f5923bda383b6b50e0a2e1b21b79a23d0bf4153 Mon Sep 17 00:00:00 2001 From: Integral Date: Tue, 24 Dec 2024 11:02:45 +0800 Subject: [PATCH] refactor: use format_args!() when String creation is unnecessary --- src/timer.rs | 26 +++++++++++++++----------- 1 file changed, 15 insertions(+), 11 deletions(-) diff --git a/src/timer.rs b/src/timer.rs index ae09a84e7..a94259768 100644 --- a/src/timer.rs +++ b/src/timer.rs @@ -108,10 +108,12 @@ impl TimerSnapshot { let mut output = String::new(); if !verbose { - output += "\n_______________________________"; - output += &format!("\nExecuted in {:6.2} {}", wall_time, wall_unit.long_name()); - output += &format!("\n usr time {:6.2} {}", usr_time, cpu_unit.long_name()); - output += &format!("\n sys time {:6.2} {}", sys_time, cpu_unit.long_name()); + output += &format!( + "\n_______________________________\n{}\n {}\n {}", + format_args!("Executed in {:6.2} {}", wall_time, wall_unit.long_name()), + format_args!("usr time {:6.2} {}", usr_time, cpu_unit.long_name()), + format_args!("sys time {:6.2} {}", sys_time, cpu_unit.long_name()), + ); } else { let fish_unit = Unit::for_micros(fish_sys.max(fish_usr).as_micros() as i64); let child_unit = Unit::for_micros(child_sys.max(child_usr).as_micros() as i64); @@ -129,15 +131,17 @@ impl TimerSnapshot { let fish_unit = fish_unit.short_name(); let child_unit = child_unit.short_name(); - output += "\n________________________________________________________"; output += &format!( - "\nExecuted in {wall_time:6.2} {wall_unit: