Skip to content

Commit

Permalink
Simplify code and fix dead code in read_bang_element
Browse files Browse the repository at this point in the history
`read` in read_bang_element was at least 1, but then branch in any case
could be reachable only if .read_buf() returns empty array, but in that
case we have already exited with the correct error
  • Loading branch information
Mingun committed Nov 12, 2023
1 parent e631de7 commit 6d5afed
Showing 1 changed file with 5 additions and 13 deletions.
18 changes: 5 additions & 13 deletions src/reader/buffered_reader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ macro_rules! impl_buffered_source {
match self $(.$reader)? .fill_buf() $(.$await)? {
// Note: Do not update position, so the error points to
// somewhere sane rather than at the EOF
Ok(n) if n.is_empty() => return Err(bang_type.to_err()),
Ok(n) if n.is_empty() => break,
Ok(available) => {
// We only parse from start because we don't want to consider
// whatever is in the buffer before the bang element
Expand All @@ -122,7 +122,7 @@ macro_rules! impl_buffered_source {
read += used;

*position += read;
break;
return Ok((bang_type, &buf[start..]));
} else {
buf.extend_from_slice(available);

Expand All @@ -139,11 +139,7 @@ macro_rules! impl_buffered_source {
}
}

if read == 0 {
Err(bang_type.to_err())
} else {
Ok((bang_type, &buf[start..]))
}
Err(bang_type.to_err())
}

#[inline]
Expand All @@ -168,7 +164,7 @@ macro_rules! impl_buffered_source {

// Position now just after the `>` symbol
*position += read;
break;
return Ok(&buf[start..]);
} else {
// The `>` symbol not yet found, continue reading
buf.extend_from_slice(available);
Expand All @@ -186,11 +182,7 @@ macro_rules! impl_buffered_source {
};
}

if read == 0 {
Err(Error::Syntax(SyntaxError::UnclosedTag))
} else {
Ok(&buf[start..])
}
Err(Error::Syntax(SyntaxError::UnclosedTag))
}

$($async)? fn skip_whitespace(&mut self, position: &mut usize) -> Result<()> {
Expand Down

0 comments on commit 6d5afed

Please sign in to comment.