Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 6 additions & 10 deletions src/uu/wc/src/count_fast.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,17 +52,13 @@ fn count_bytes_using_splice(fd: &impl AsFd) -> Result<usize, usize> {
}
}
let (pipe_rd, pipe_wr) = pipe::<false>(MAX_ROOTLESS_PIPE_SIZE).map_err(|_| byte_count)?;
loop {
match splice(fd, &pipe_wr, MAX_ROOTLESS_PIPE_SIZE).map_err(|_| byte_count)? {
0 => return Ok(byte_count),
res => {
byte_count += res;
// pipe to null is not blocked. So this returns res at most cases
// next splice does not hang if we discarded 1+ pages
splice(&pipe_rd, &null_file, res).map_err(|_| byte_count)?;
}
}
while let s @ 1.. = splice(fd, &pipe_wr, MAX_ROOTLESS_PIPE_SIZE).map_err(|_| byte_count)? {
byte_count += s;
// pipe to null is not blocked. So this returns the same length at most cases
// next splice does not hang if we discarded 1+ pages
splice(&pipe_rd, &null_file, s).map_err(|_| byte_count)?;
}
Ok(byte_count)
}

/// In the special case where we only need to count the number of bytes. There
Expand Down
Loading