diff --git a/src/uu/cat/src/splice.rs b/src/uu/cat/src/splice.rs index 87cbff81a3e..4bb144ee40a 100644 --- a/src/uu/cat/src/splice.rs +++ b/src/uu/cat/src/splice.rs @@ -23,6 +23,8 @@ pub(super) fn write_fast_using_splice( handle: &InputHandle, write_fd: &S, ) -> CatResult { + use std::{fs::File, sync::OnceLock}; + static BROKER: OnceLock> = OnceLock::new(); if splice(&handle.reader, &write_fd, MAX_ROOTLESS_PIPE_SIZE).is_ok() { // fcntl improves throughput // todo: avoid fcntl overhead for small input, but don't fcntl inside of the loop @@ -34,7 +36,7 @@ pub(super) fn write_fast_using_splice( Err(_) => return Ok(true), } } - } else if let Ok((pipe_rd, pipe_wr)) = pipe() { + } else if let Some((pipe_rd, pipe_wr)) = BROKER.get_or_init(|| pipe().ok()).as_ref() { // both of in/output are not pipe. needs broker to use splice() with additional costs loop { match splice(&handle.reader, &pipe_wr, MAX_ROOTLESS_PIPE_SIZE) {