mirror of
https://github.com/sharkdp/bat
synced 2026-08-07 19:31:42 +00:00
Reduce nesting in if blocks by short circuiting
This commit is contained in:
committed by
Martin Nordholts
parent
9124271eaf
commit
372e42f350
+10
-10
@@ -256,18 +256,18 @@ impl<'a> InputReader<'a> {
|
||||
}
|
||||
|
||||
pub(crate) fn read_line(&mut self, buf: &mut Vec<u8>) -> io::Result<bool> {
|
||||
if self.first_line.is_empty() {
|
||||
let res = self.inner.read_until(b'\n', buf).map(|size| size > 0)?;
|
||||
|
||||
if self.content_type == Some(ContentType::UTF_16LE) {
|
||||
self.inner.read_until(0x00, buf).ok();
|
||||
}
|
||||
|
||||
Ok(res)
|
||||
} else {
|
||||
if !self.first_line.is_empty() {
|
||||
buf.append(&mut self.first_line);
|
||||
Ok(true)
|
||||
return Ok(true);
|
||||
}
|
||||
|
||||
let res = self.inner.read_until(b'\n', buf).map(|size| size > 0)?;
|
||||
|
||||
if self.content_type == Some(ContentType::UTF_16LE) {
|
||||
let _ = self.inner.read_until(0x00, buf);
|
||||
}
|
||||
|
||||
Ok(res)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user