Skip to content

Commit 6d5afed

Browse files
committed
Simplify code and fix dead code in read_bang_element
`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
1 parent e631de7 commit 6d5afed

File tree

1 file changed

+5
-13
lines changed

1 file changed

+5
-13
lines changed

src/reader/buffered_reader.rs

+5-13
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ macro_rules! impl_buffered_source {
111111
match self $(.$reader)? .fill_buf() $(.$await)? {
112112
// Note: Do not update position, so the error points to
113113
// somewhere sane rather than at the EOF
114-
Ok(n) if n.is_empty() => return Err(bang_type.to_err()),
114+
Ok(n) if n.is_empty() => break,
115115
Ok(available) => {
116116
// We only parse from start because we don't want to consider
117117
// whatever is in the buffer before the bang element
@@ -122,7 +122,7 @@ macro_rules! impl_buffered_source {
122122
read += used;
123123

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

@@ -139,11 +139,7 @@ macro_rules! impl_buffered_source {
139139
}
140140
}
141141

142-
if read == 0 {
143-
Err(bang_type.to_err())
144-
} else {
145-
Ok((bang_type, &buf[start..]))
146-
}
142+
Err(bang_type.to_err())
147143
}
148144

149145
#[inline]
@@ -168,7 +164,7 @@ macro_rules! impl_buffered_source {
168164

169165
// Position now just after the `>` symbol
170166
*position += read;
171-
break;
167+
return Ok(&buf[start..]);
172168
} else {
173169
// The `>` symbol not yet found, continue reading
174170
buf.extend_from_slice(available);
@@ -186,11 +182,7 @@ macro_rules! impl_buffered_source {
186182
};
187183
}
188184

189-
if read == 0 {
190-
Err(Error::Syntax(SyntaxError::UnclosedTag))
191-
} else {
192-
Ok(&buf[start..])
193-
}
185+
Err(Error::Syntax(SyntaxError::UnclosedTag))
194186
}
195187

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

0 commit comments

Comments
 (0)