From 3136627d5262b74a12e81b9ce6abfe9b441b8dfc Mon Sep 17 00:00:00 2001 From: oech3 <79379754+oech3@users.noreply.github.com> Date: Thu, 5 Mar 2026 21:01:23 +0900 Subject: [PATCH] =?UTF-8?q?true,=20false:=20Improve=20perf=20&=20fix=20cli?= =?UTF-8?q?ppy::unnecessary=5Fwraps=20-=20=20improve=20performance=20by=20?= =?UTF-8?q?=C3=9739=20(#11200)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/uu/false/src/false.rs | 22 ++++++---------------- src/uu/true/src/true.rs | 18 +++++++----------- 2 files changed, 13 insertions(+), 27 deletions(-) diff --git a/src/uu/false/src/false.rs b/src/uu/false/src/false.rs index 097e01de3..0fc90364a 100644 --- a/src/uu/false/src/false.rs +++ b/src/uu/false/src/false.rs @@ -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 = 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 { diff --git a/src/uu/true/src/true.rs b/src/uu/true/src/true.rs index 7a4da1810..626073c21 100644 --- a/src/uu/true/src/true.rs +++ b/src/uu/true/src/true.rs @@ -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 = 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 {