From cbd31e39166dba050ce277dec2a7de2fb5d923f2 Mon Sep 17 00:00:00 2001 From: oech3 <79379754+oech3@users.noreply.github.com> Date: Fri, 15 May 2026 02:20:23 +0900 Subject: [PATCH] yes: reduce lines by cfg --- src/uu/yes/src/yes.rs | 29 ++++++++++++----------------- 1 file changed, 12 insertions(+), 17 deletions(-) diff --git a/src/uu/yes/src/yes.rs b/src/uu/yes/src/yes.rs index 22508a1b28..5d8c454907 100644 --- a/src/uu/yes/src/yes.rs +++ b/src/uu/yes/src/yes.rs @@ -56,29 +56,24 @@ pub fn uu_app() -> Command { /// create a buffer filled by words `i` separated by spaces. #[allow(clippy::unnecessary_wraps, reason = "needed on some platforms")] fn args_into_buffer<'a>(i: impl Iterator) -> UResult> { + #[cfg(unix)] + use std::os::unix::ffi::OsStrExt; + #[cfg(target_os = "wasi")] + use std::os::wasi::ffi::OsStrExt; + let mut buf = Vec::with_capacity(BUF_SIZE); // On Unix (and wasi), OsStrs are just &[u8]'s underneath... #[cfg(any(unix, target_os = "wasi"))] - { - #[cfg(unix)] - use std::os::unix::ffi::OsStrExt; - #[cfg(target_os = "wasi")] - use std::os::wasi::ffi::OsStrExt; - - for part in itertools::intersperse(i.map(|a| a.as_bytes()), b" ") { - buf.extend_from_slice(part); - } + for part in itertools::intersperse(i.map(|a| a.as_bytes()), b" ") { + buf.extend_from_slice(part); } - // But, on Windows, we must hop through a String. #[cfg(not(any(unix, target_os = "wasi")))] - { - for part in itertools::intersperse(i.map(|a| a.to_str()), Some(" ")) { - let bytes = part - .ok_or_else(|| USimpleError::new(1, translate!("yes-error-invalid-utf8")))? - .as_bytes(); - buf.extend_from_slice(bytes); - } + for part in itertools::intersperse(i.map(|a| a.to_str()), Some(" ")) { + let bytes = part + .ok_or_else(|| USimpleError::new(1, translate!("yes-error-invalid-utf8")))? + .as_bytes(); + buf.extend_from_slice(bytes); } buf.push(b'\n');