Skip to content

Commit f08652f

Browse files
oech3cakebaker
authored andcommitted
head: remove collapsible_if
1 parent 9a9c228 commit f08652f

2 files changed

Lines changed: 15 additions & 22 deletions

File tree

src/uu/head/src/head.rs

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -309,15 +309,13 @@ where
309309
// obviously found our 0th-line-from-the-end offset.
310310
if check_last_byte_first_loop {
311311
check_last_byte_first_loop = false;
312-
if let Some(last_byte_of_file) = buffer.last() {
313-
if last_byte_of_file != &separator {
314-
if n == 0 {
315-
input.rewind()?;
316-
return Ok(file_size);
317-
}
318-
assert_eq!(lines, 0);
319-
lines = 1;
312+
if buffer.last().is_some_and(|&b| b != separator) {
313+
if n == 0 {
314+
input.rewind()?;
315+
return Ok(file_size);
320316
}
317+
assert_eq!(lines, 0);
318+
lines = 1;
321319
}
322320
}
323321

src/uu/head/src/take.rs

Lines changed: 9 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -104,10 +104,8 @@ pub fn copy_all_but_n_bytes(
104104
loop {
105105
// Try to buffer at least enough to write the entire first buffer.
106106
let front_buffer = buffers.front();
107-
if let Some(front_buffer) = front_buffer {
108-
if buffered_bytes >= n + front_buffer.remaining_bytes() {
109-
break;
110-
}
107+
if front_buffer.is_some_and(|b| buffered_bytes >= n + b.remaining_bytes()) {
108+
break;
111109
}
112110
let mut new_buffer = empty_buffer_pool.pop().unwrap_or_else(TakeAllBuffer::new);
113111
let filled_bytes = new_buffer.fill_buffer(reader)?;
@@ -163,15 +161,14 @@ impl TakeAllLinesBuffer {
163161
reader: &mut impl Read,
164162
separator: u8,
165163
) -> std::io::Result<BytesAndLines> {
166-
self.partial_line = false;
167164
let bytes_read = self.inner.fill_buffer(reader)?;
168165
// Count the number of lines...
169166
self.terminated_lines = memchr_iter(separator, self.inner.remaining_buffer()).count();
170-
if let Some(last_char) = self.inner.remaining_buffer().last() {
171-
if *last_char != separator {
172-
self.partial_line = true;
173-
}
174-
}
167+
self.partial_line = self
168+
.inner
169+
.remaining_buffer()
170+
.last()
171+
.is_some_and(|&c| c != separator);
175172
Ok(BytesAndLines {
176173
bytes: bytes_read,
177174
terminated_lines: self.terminated_lines,
@@ -266,10 +263,8 @@ pub fn copy_all_but_n_lines<R: Read, W: Write>(
266263
// First check if we have enough lines buffered that we can write out the entire
267264
// front buffer. If so, break.
268265
let front_buffer = buffers.front();
269-
if let Some(front_buffer) = front_buffer {
270-
if buffered_terminated_lines > n + front_buffer.terminated_lines() {
271-
break;
272-
}
266+
if front_buffer.is_some_and(|b| buffered_terminated_lines > n + b.terminated_lines()) {
267+
break;
273268
}
274269
// Else we need to try to buffer more data...
275270
let mut new_buffer = empty_buffers.pop().unwrap_or_else(TakeAllLinesBuffer::new);

0 commit comments

Comments
 (0)