Skip to content

Commit 128d3bc

Browse files
committed
read 16 KiB at once
1 parent 4377d44 commit 128d3bc

1 file changed

Lines changed: 6 additions & 7 deletions

File tree

src/uu/cat/src/cat.rs

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -482,12 +482,11 @@ fn write_fast<R: FdReadable>(handle: &mut InputHandle<R>) -> CatResult<()> {
482482
#[cfg(any(target_os = "linux", target_os = "android"))]
483483
{
484484
// splice is slow for small files (https://github.com/uutils/coreutils/issues/10832)
485-
const SPLICE_THRESHOLD: u64 = 16 * 1024;
486-
let copied = io::copy(
487-
&mut handle.reader.by_ref().take(SPLICE_THRESHOLD),
488-
&mut stdout_lock,
489-
)?;
490-
if copied < SPLICE_THRESHOLD {
485+
const SPLICE_THRESHOLD: usize = 16 * 1024;
486+
let mut buf = [0; SPLICE_THRESHOLD];
487+
let n = handle.reader.read(&mut buf)?;
488+
stdout_lock.write_all(&buf[..n])?;
489+
if n < SPLICE_THRESHOLD {
491490
stdout_lock.flush()?;
492491
return Ok(());
493492
}
@@ -498,7 +497,7 @@ fn write_fast<R: FdReadable>(handle: &mut InputHandle<R>) -> CatResult<()> {
498497
}
499498
// If we're not on Linux or Android, or the splice() call failed,
500499
// fall back on slower writing.
501-
let mut buf = [0; 1024 * 64];
500+
let mut buf = vec![0; 1024 * 64];
502501
loop {
503502
match handle.reader.read(&mut buf) {
504503
Ok(n) => {

0 commit comments

Comments
 (0)