Skip to content

Commit 5ca5e01

Browse files
oech3sylvestre
authored andcommitted
cat: simplify splice & fix comment
1 parent 7712f42 commit 5ca5e01

1 file changed

Lines changed: 6 additions & 10 deletions

File tree

src/uu/cat/src/splice.rs

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,9 @@ pub(super) fn write_fast_using_splice<R: FdReadable, S: AsRawFd + AsFd>(
2323
handle: &InputHandle<R>,
2424
write_fd: &S,
2525
) -> CatResult<bool> {
26-
const FIRST_PIPE_SIZE: usize = 64 * 1024;
27-
if splice(&handle.reader, &write_fd, FIRST_PIPE_SIZE).is_ok() {
28-
// fcntl improves performance for large file which is large overhead for small files
26+
if splice(&handle.reader, &write_fd, MAX_ROOTLESS_PIPE_SIZE).is_ok() {
27+
// fcntl improves throughput
28+
// todo: avoid fcntl overhead for small input, but don't fcntl inside of the loop
2929
let _ = rustix::pipe::fcntl_setpipe_size(write_fd, MAX_ROOTLESS_PIPE_SIZE);
3030
loop {
3131
match splice(&handle.reader, &write_fd, MAX_ROOTLESS_PIPE_SIZE) {
@@ -35,14 +35,12 @@ pub(super) fn write_fast_using_splice<R: FdReadable, S: AsRawFd + AsFd>(
3535
}
3636
}
3737
} else {
38-
// output is not pipe. Needs broker to use splice() which is high cost for small files
38+
// both of in/output are not pipe. needs broker to use splice() with additional costs
3939
let (pipe_rd, pipe_wr) = pipe()?;
4040
loop {
4141
match splice(&handle.reader, &pipe_wr, MAX_ROOTLESS_PIPE_SIZE) {
42+
Ok(0) => return Ok(false),
4243
Ok(n) => {
43-
if n == 0 {
44-
return Ok(false);
45-
}
4644
if splice_exact(&pipe_rd, write_fd, n).is_err() {
4745
// If the first splice manages to copy to the intermediate
4846
// pipe, but the second splice to stdout fails for some reason
@@ -53,9 +51,7 @@ pub(super) fn write_fast_using_splice<R: FdReadable, S: AsRawFd + AsFd>(
5351
return Ok(true);
5452
}
5553
}
56-
Err(_) => {
57-
return Ok(true);
58-
}
54+
Err(_) => return Ok(true),
5955
}
6056
}
6157
}

0 commit comments

Comments
 (0)