mirror of
https://github.com/uutils/coreutils.git
synced 2026-05-06 07:26:38 -04:00
cat: call pipe() once with multiple input (#11699)
This commit is contained in:
@@ -21,6 +21,8 @@ pub(super) fn write_fast_using_splice<R: FdReadable, S: AsRawFd + AsFd + Write>(
|
||||
handle: &InputHandle<R>,
|
||||
write_fd: &mut S,
|
||||
) -> CatResult<bool> {
|
||||
use std::{fs::File, sync::OnceLock};
|
||||
static PIPE_CACHE: OnceLock<Option<(File, File)>> = 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
|
||||
@@ -32,7 +34,7 @@ pub(super) fn write_fast_using_splice<R: FdReadable, S: AsRawFd + AsFd + Write>(
|
||||
Err(_) => return Ok(true),
|
||||
}
|
||||
}
|
||||
} else if let Ok((pipe_rd, pipe_wr)) = pipe() {
|
||||
} else if let Some((pipe_rd, pipe_wr)) = PIPE_CACHE.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) {
|
||||
|
||||
Reference in New Issue
Block a user