mirror of
https://github.com/uutils/coreutils.git
synced 2026-06-10 15:48:22 -07:00
tail: improve throughput for -c +0 (#11962)
This commit is contained in:
@@ -33,6 +33,9 @@ notify = { workspace = true }
|
||||
[target.'cfg(unix)'.dependencies]
|
||||
rustix = { workspace = true, features = ["fs", "process"] }
|
||||
|
||||
[target.'cfg(any(target_os = "linux", target_os = "android"))'.dependencies]
|
||||
uucore = { workspace = true, features = ["pipes"] }
|
||||
|
||||
[target.'cfg(windows)'.dependencies]
|
||||
windows-sys = { workspace = true, features = [
|
||||
"Win32_System_Threading",
|
||||
|
||||
+14
-5
@@ -575,17 +575,26 @@ fn unbounded_tail<T: Read>(reader: &mut BufReader<T>, settings: &Settings) -> UR
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn print_target_section<R>(file: &mut R, limit: Option<u64>) -> UResult<()>
|
||||
where
|
||||
R: Read + ?Sized,
|
||||
{
|
||||
// Print the target section of the file.
|
||||
// Print the target section of the file
|
||||
fn print_target_section<
|
||||
#[cfg(any(target_os = "linux", target_os = "android"))] R: Read + rustix::fd::AsFd,
|
||||
#[cfg(not(any(target_os = "linux", target_os = "android")))] R: Read + ?Sized,
|
||||
>(
|
||||
file: &mut R,
|
||||
limit: Option<u64>,
|
||||
) -> UResult<()> {
|
||||
let stdout = stdout();
|
||||
let mut stdout = stdout.lock();
|
||||
if let Some(limit) = limit {
|
||||
let mut reader = file.take(limit);
|
||||
io::copy(&mut reader, &mut stdout)?;
|
||||
} else {
|
||||
// zero-copy fast-path
|
||||
#[cfg(any(target_os = "linux", target_os = "android"))]
|
||||
if uucore::pipes::splice_unbounded_broker(file, &mut stdout)? {
|
||||
io::copy(file, &mut stdout)?;
|
||||
}
|
||||
#[cfg(not(any(target_os = "linux", target_os = "android")))]
|
||||
io::copy(file, &mut stdout)?;
|
||||
}
|
||||
Ok(())
|
||||
|
||||
Reference in New Issue
Block a user