From 9eee8987cb619e096c52876b6d30c8769031f2ee Mon Sep 17 00:00:00 2001 From: oech3 <79379754+oech3@users.noreply.github.com> Date: Sat, 7 Mar 2026 13:48:28 +0900 Subject: [PATCH] true, false: drop Vec for binary size and perf --- src/uu/false/src/false.rs | 15 +++++++-------- src/uu/true/src/true.rs | 15 +++++++-------- 2 files changed, 14 insertions(+), 16 deletions(-) diff --git a/src/uu/false/src/false.rs b/src/uu/false/src/false.rs index 98699edd08b..c17e2f13051 100644 --- a/src/uu/false/src/false.rs +++ b/src/uu/false/src/false.rs @@ -3,20 +3,19 @@ // For the full copyright and license information, please view the LICENSE // file that was distributed with this source code. use clap::{Arg, ArgAction, Command}; -use std::{ffi::OsString, io::Write}; +use std::io::Write; use uucore::translate; // uucore::main does not support no-result -pub fn uumain(args: impl uucore::Args) -> i32 { - let args: Vec = args.collect(); - if args.len() != 2 { +pub fn uumain(mut args: impl uucore::Args) -> i32 { + // skip binary name + let (Some(flag), None) = (args.nth(1), args.next()) else { return 1; - } + }; - // args[0] is the name of the binary. - let error = if args[1] == "--help" { + let error = if flag == "--help" { uu_app().print_help() - } else if args[1] == "--version" { + } else if flag == "--version" { write!(std::io::stdout(), "{}", uu_app().render_version()) } else { return 1; diff --git a/src/uu/true/src/true.rs b/src/uu/true/src/true.rs index 463a76d52f9..b96392a1a7d 100644 --- a/src/uu/true/src/true.rs +++ b/src/uu/true/src/true.rs @@ -3,20 +3,19 @@ // For the full copyright and license information, please view the LICENSE // file that was distributed with this source code. use clap::{Arg, ArgAction, Command}; -use std::{ffi::OsString, io::Write}; +use std::io::Write; use uucore::translate; // uucore::main does not support no-result -pub fn uumain(args: impl uucore::Args) -> i32 { - let args: Vec = args.collect(); - if args.len() != 2 { +pub fn uumain(mut args: impl uucore::Args) -> i32 { + // skip binary name + let (Some(flag), None) = (args.nth(1), args.next()) else { return 0; - } + }; - // args[0] is the name of the binary. - let error = if args[1] == "--help" { + let error = if flag == "--help" { uu_app().print_help() - } else if args[1] == "--version" { + } else if flag == "--version" { write!(std::io::stdout(), "{}", uu_app().render_version()) } else { return 0;