optimizations #161

Open
emma wants to merge 44 commits from optimizations into main
Showing only changes of commit 722679247a - Show all commits

View File

@ -90,7 +90,7 @@ fn main() -> ExitCode {
let promises = Promises::new("stdio");
if let Err(e) = pledge(Some(promises), None) {
eprintln!("{}: {}", argv[0], e.strerror());
return ExitCode::from(EX_OSERR as u8);
return ExitCode::from(EX_OSERR);
}
}
@ -104,30 +104,26 @@ fn main() -> ExitCode {
buf.clear();
f
},
Err(err) => {
eprintln!("{}: {}", argv[0], err);
return ExitCode::from(EX_DATAERR as u8);
Err(e) => {
eprintln!("{}: {}", argv[0], e);
return ExitCode::from(EX_DATAERR);
},
};
let (number, prefix) = match convert(n) {
Ok(x) => x,
Err(err) => {
eprintln!("{}: {}", argv[0], err);
return ExitCode::from(EX_SOFTWARE as u8);
},
};
let (number, prefix) = convert(n).unwrap_or_else(|e| {
eprintln!("{}: {}", argv[0], e);
exit(EX_SOFTWARE.into());
});
let si_prefix = format!("{}B", prefix.1);
/* round output number to one decimal place */
let out = ((number * 10.0).round() / 10.0).to_string();
stdout().write_all(format!("{} {}\n", out, si_prefix).as_bytes())
.unwrap_or_else(|e| {
eprintln!("{}: {}", argv[0], e.strerror());
exit(EX_IOERR);
});
if let Err(e) = stdout().write_all(format!("{} {}\n", out, si_prefix).as_bytes()) {
eprintln!("{}: {}", argv[0], e.strerror());
return ExitCode::from(EX_IOERR);
}
}
ExitCode::SUCCESS