Skip to content

Commit cdcbee3

Browse files
authored
tail: improve throughput for -c +0 (#11962)
1 parent 5275ffd commit cdcbee3

2 files changed

Lines changed: 17 additions & 5 deletions

File tree

src/uu/tail/Cargo.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,9 @@ notify = { workspace = true }
3333
[target.'cfg(unix)'.dependencies]
3434
rustix = { workspace = true, features = ["fs", "process"] }
3535

36+
[target.'cfg(any(target_os = "linux", target_os = "android"))'.dependencies]
37+
uucore = { workspace = true, features = ["pipes"] }
38+
3639
[target.'cfg(windows)'.dependencies]
3740
windows-sys = { workspace = true, features = [
3841
"Win32_System_Threading",

src/uu/tail/src/tail.rs

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -575,17 +575,26 @@ fn unbounded_tail<T: Read>(reader: &mut BufReader<T>, settings: &Settings) -> UR
575575
Ok(())
576576
}
577577

578-
fn print_target_section<R>(file: &mut R, limit: Option<u64>) -> UResult<()>
579-
where
580-
R: Read + ?Sized,
581-
{
582-
// Print the target section of the file.
578+
// Print the target section of the file
579+
fn print_target_section<
580+
#[cfg(any(target_os = "linux", target_os = "android"))] R: Read + rustix::fd::AsFd,
581+
#[cfg(not(any(target_os = "linux", target_os = "android")))] R: Read + ?Sized,
582+
>(
583+
file: &mut R,
584+
limit: Option<u64>,
585+
) -> UResult<()> {
583586
let stdout = stdout();
584587
let mut stdout = stdout.lock();
585588
if let Some(limit) = limit {
586589
let mut reader = file.take(limit);
587590
io::copy(&mut reader, &mut stdout)?;
588591
} else {
592+
// zero-copy fast-path
593+
#[cfg(any(target_os = "linux", target_os = "android"))]
594+
if uucore::pipes::splice_unbounded_broker(file, &mut stdout)? {
595+
io::copy(file, &mut stdout)?;
596+
}
597+
#[cfg(not(any(target_os = "linux", target_os = "android")))]
589598
io::copy(file, &mut stdout)?;
590599
}
591600
Ok(())

0 commit comments

Comments
 (0)