Skip to content

Commit 55549fa

Browse files
oech3cakebaker
authored andcommitted
wc: remove a nest by loop{}
1 parent b22013a commit 55549fa

1 file changed

Lines changed: 6 additions & 10 deletions

File tree

src/uu/wc/src/count_fast.rs

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -52,17 +52,13 @@ fn count_bytes_using_splice(fd: &impl AsFd) -> Result<usize, usize> {
5252
}
5353
}
5454
let (pipe_rd, pipe_wr) = pipe::<false>(MAX_ROOTLESS_PIPE_SIZE).map_err(|_| byte_count)?;
55-
loop {
56-
match splice(fd, &pipe_wr, MAX_ROOTLESS_PIPE_SIZE).map_err(|_| byte_count)? {
57-
0 => return Ok(byte_count),
58-
res => {
59-
byte_count += res;
60-
// pipe to null is not blocked. So this returns res at most cases
61-
// next splice does not hang if we discarded 1+ pages
62-
splice(&pipe_rd, &null_file, res).map_err(|_| byte_count)?;
63-
}
64-
}
55+
while let s @ 1.. = splice(fd, &pipe_wr, MAX_ROOTLESS_PIPE_SIZE).map_err(|_| byte_count)? {
56+
byte_count += s;
57+
// pipe to null is not blocked. So this returns the same length at most cases
58+
// next splice does not hang if we discarded 1+ pages
59+
splice(&pipe_rd, &null_file, s).map_err(|_| byte_count)?;
6560
}
61+
Ok(byte_count)
6662
}
6763

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

0 commit comments

Comments
 (0)