Address clippy lints

We want to keep the cast because tv_sec is not always 64 bits, see b5ff175b4
(Fix timer.rs cross-platform compilation, 2023-02-14).
It would be nice to avoid the clippy exemption, perhaps using something like

    #[cfg(target_pointer_width = "32")]
    let seconds = val.tv_sec as i64;
    #[cfg(not(target_pointer_width = "32"))]
    let seconds = val.tv_sec;

but I'm not sure if "target_pointer_width" is the right criteria.
This commit is contained in:
Johannes Altmanninger 2023-02-18 08:11:05 +01:00
parent b7041ad89b
commit 0d6b53bc3e
2 changed files with 20 additions and 21 deletions

View file

@ -2,6 +2,7 @@
use std::time::Duration;
#[allow(clippy::unnecessary_cast)]
pub const fn timeval_to_duration(val: &libc::timeval) -> Duration {
let micros = val.tv_sec as i64 * (1E6 as i64) + val.tv_usec as i64;
Duration::from_micros(micros as u64)

View file

@ -137,7 +137,7 @@ impl TimerSnapshot {
let mut output = String::new();
if !verbose {
output += &"\n_______________________________";
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());
@ -158,17 +158,15 @@ impl TimerSnapshot {
let fish_unit = fish_unit.short_name();
let child_unit = child_unit.short_name();
output += &"\n________________________________________________________";
output += "\n________________________________________________________";
output += &format!(
"\nExecuted in {wall_time:6.2} {wall_unit:<width1$} {fish:<width2$} external",
width1 = column2_unit_len,
fish = "fish",
width2 = fish_unit.len() + 7
);
output += &format!("\n usr time {usr_time:6.2} {cpu_unit:<width1$} {fish_usr_time:6.2} {fish_unit} {child_usr_time:6.2} {child_unit}",
width1 = column2_unit_len);
output += &format!("\n sys time {sys_time:6.2} {cpu_unit:<width1$} {fish_sys_time:6.2} {fish_unit} {child_sys_time:6.2} {child_unit}",
width1 = column2_unit_len);
output += &format!("\n usr time {usr_time:6.2} {cpu_unit:<column2_unit_len$} {fish_usr_time:6.2} {fish_unit} {child_usr_time:6.2} {child_unit}");
output += &format!("\n sys time {sys_time:6.2} {cpu_unit:<column2_unit_len$} {fish_sys_time:6.2} {fish_unit} {child_sys_time:6.2} {child_unit}");
}
output += "\n";
@ -209,29 +207,29 @@ impl Unit {
}
const fn short_name(&self) -> &'static str {
match self {
&Unit::Minutes => "mins",
&Unit::Seconds => "secs",
&Unit::Millis => "millis",
&Unit::Micros => "micros",
match *self {
Unit::Minutes => "mins",
Unit::Seconds => "secs",
Unit::Millis => "millis",
Unit::Micros => "micros",
}
}
const fn long_name(&self) -> &'static str {
match self {
&Unit::Minutes => "minutes",
&Unit::Seconds => "seconds",
&Unit::Millis => "milliseconds",
&Unit::Micros => "microseconds",
match *self {
Unit::Minutes => "minutes",
Unit::Seconds => "seconds",
Unit::Millis => "milliseconds",
Unit::Micros => "microseconds",
}
}
fn convert_micros(&self, micros: i64) -> f64 {
match self {
&Unit::Minutes => micros as f64 / 1.0E6 / 60.0,
&Unit::Seconds => micros as f64 / 1.0E6,
&Unit::Millis => micros as f64 / 1.0E3,
&Unit::Micros => micros as f64 / 1.0,
match *self {
Unit::Minutes => micros as f64 / 1.0E6 / 60.0,
Unit::Seconds => micros as f64 / 1.0E6,
Unit::Millis => micros as f64 / 1.0E3,
Unit::Micros => micros as f64 / 1.0,
}
}
}