Skip to content

Commit 2f7f16a

Browse files
committed
cat: avoid unnecessary allocation
1 parent 13ef3e8 commit 2f7f16a

File tree

1 file changed

+4
-0
lines changed

1 file changed

+4
-0
lines changed

src/uu/cat/src/cat.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -489,6 +489,10 @@ fn write_fast<R: FdReadable>(handle: &mut InputHandle<R>) -> CatResult<()> {
489489
// If we're not on Linux or Android, or the splice() call failed,
490490
// fall back on slower writing.
491491
let mut stdout_lock = stdout.lock();
492+
// stack allocaltion is overhead when splice succeed
493+
#[cfg(any(target_os = "linux", target_os = "android"))]
494+
let mut buf = vec![0; 1024 * 64];
495+
#[cfg(not(any(target_os = "linux", target_os = "android")))]
492496
let mut buf = [0; 1024 * 64];
493497
loop {
494498
match handle.reader.read(&mut buf) {

0 commit comments

Comments
 (0)