1
0
mirror of https://github.com/sharkdp/bat.git synced 2025-09-02 19:32:25 +01:00

Reduce nesting in if blocks by short circuiting

This commit is contained in:
Marcin Puc
2021-09-10 21:52:09 +02:00
committed by Martin Nordholts
parent 9124271eaf
commit 372e42f350
5 changed files with 80 additions and 84 deletions

View File

@@ -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)
}
}