mirror of
https://github.com/uutils/coreutils.git
synced 2026-06-10 15:48:22 -07:00
true, false: Improve perf & fix clippy::unnecessary_wraps - improve performance by ×39 (#11200)
This commit is contained in:
@@ -4,23 +4,14 @@
|
||||
// file that was distributed with this source code.
|
||||
use clap::{Arg, ArgAction, Command};
|
||||
use std::{ffi::OsString, io::Write};
|
||||
use uucore::error::{UResult, set_exit_code};
|
||||
|
||||
use uucore::translate;
|
||||
|
||||
#[uucore::main(no_signals)]
|
||||
// TODO: modify proc macro to allow no-result uumain
|
||||
#[expect(clippy::unnecessary_wraps, reason = "proc macro requires UResult")]
|
||||
pub fn uumain(args: impl uucore::Args) -> UResult<()> {
|
||||
// Mirror GNU options, always return `1`. In particular even the 'successful' cases of no-op,
|
||||
// and the interrupted display of help and version should return `1`. Also, we return Ok in all
|
||||
// paths to avoid the allocation of an error object, an operation that could, in theory, fail
|
||||
// and unwind through the standard library allocation handling machinery.
|
||||
set_exit_code(1);
|
||||
|
||||
// uucore::main does not support no-result
|
||||
// also remove SIGPIPE overhead
|
||||
pub fn uumain(args: impl uucore::Args) -> i32 {
|
||||
let args: Vec<OsString> = args.collect();
|
||||
if args.len() != 2 {
|
||||
return Ok(());
|
||||
return 1;
|
||||
}
|
||||
|
||||
// args[0] is the name of the binary.
|
||||
@@ -29,14 +20,13 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> {
|
||||
} else if args[1] == "--version" {
|
||||
write!(std::io::stdout(), "{}", uu_app().render_version())
|
||||
} else {
|
||||
Ok(())
|
||||
return 1;
|
||||
};
|
||||
|
||||
if let Err(print_fail) = error {
|
||||
let _ = writeln!(std::io::stderr(), "{}: {print_fail}", uucore::util_name());
|
||||
}
|
||||
|
||||
Ok(())
|
||||
1
|
||||
}
|
||||
|
||||
pub fn uu_app() -> Command {
|
||||
|
||||
+7
-11
@@ -4,17 +4,14 @@
|
||||
// file that was distributed with this source code.
|
||||
use clap::{Arg, ArgAction, Command};
|
||||
use std::{ffi::OsString, io::Write};
|
||||
use uucore::error::{UResult, set_exit_code};
|
||||
|
||||
use uucore::translate;
|
||||
|
||||
#[uucore::main(no_signals)]
|
||||
// TODO: modify proc macro to allow no-result uumain
|
||||
#[expect(clippy::unnecessary_wraps, reason = "proc macro requires UResult")]
|
||||
pub fn uumain(args: impl uucore::Args) -> UResult<()> {
|
||||
// uucore::main does not support no-result
|
||||
// also remove SIGPIPE overhead
|
||||
pub fn uumain(args: impl uucore::Args) -> i32 {
|
||||
let args: Vec<OsString> = args.collect();
|
||||
if args.len() != 2 {
|
||||
return Ok(());
|
||||
return 0;
|
||||
}
|
||||
|
||||
// args[0] is the name of the binary.
|
||||
@@ -23,7 +20,7 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> {
|
||||
} else if args[1] == "--version" {
|
||||
write!(std::io::stdout(), "{}", uu_app().render_version())
|
||||
} else {
|
||||
Ok(())
|
||||
return 0;
|
||||
};
|
||||
|
||||
if let Err(print_fail) = error {
|
||||
@@ -32,10 +29,9 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> {
|
||||
// Mirror GNU options. When failing to print warnings or version flags, then we exit
|
||||
// with FAIL. This avoids allocation some error information which may result in yet
|
||||
// other types of failure.
|
||||
set_exit_code(1);
|
||||
return 1;
|
||||
}
|
||||
|
||||
Ok(())
|
||||
0
|
||||
}
|
||||
|
||||
pub fn uu_app() -> Command {
|
||||
|
||||
Reference in New Issue
Block a user