Skip to content

Commit

Permalink
Remove unnecessary loop from ReadDecoder.decode_next.
Browse files Browse the repository at this point in the history
Before this commit `fn decode_next` would `loop` to skip
`Decoded::Nothing` events.  This is unnecessary, because all the callers
of `decode_next` already account for `Decoded::Nothing` (explicitly or
implicitly via a wildcard).
  • Loading branch information
anforowicz committed Oct 9, 2024
1 parent c120416 commit 8f3de8a
Showing 1 changed file with 8 additions and 13 deletions.
21 changes: 8 additions & 13 deletions src/decoder/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -307,20 +307,15 @@ impl<R: Read> ReadDecoder<R> {
/// Returns the next decoded chunk. If the chunk is an ImageData chunk, its contents are written
/// into image_data.
fn decode_next(&mut self, image_data: &mut Vec<u8>) -> Result<Decoded, DecodingError> {
loop {
let (consumed, result) = {
let buf = self.reader.fill_buf()?;
if buf.is_empty() {
return Err(DecodingError::IoError(ErrorKind::UnexpectedEof.into()));
}
self.decoder.update(buf, image_data)?
};
self.reader.consume(consumed);
match result {
Decoded::Nothing => (),
result => return Ok(result),
let (consumed, result) = {
let buf = self.reader.fill_buf()?;
if buf.is_empty() {
return Err(DecodingError::IoError(ErrorKind::UnexpectedEof.into()));
}
}
self.decoder.update(buf, image_data)?
};
self.reader.consume(consumed);
Ok(result)
}

pub fn read_header_info(&mut self) -> Result<&Info<'static>, DecodingError> {
Expand Down

0 comments on commit 8f3de8a

Please sign in to comment.