Move consuming inside of match arm
@@ -1128,7 +1128,7 @@ impl<'b, 'i, R: BufRead + 'i> BufferedInput<'b, 'i, &'b mut Vec<u8>> for R {
let start = buf.len();
while !done {
- let used = match self.fill_buf() {
+ match self.fill_buf() {
Ok(n) if n.is_empty() => {
if read == 0 {
return Ok(None);
@@ -1140,10 +1140,15 @@ impl<'b, 'i, R: BufRead + 'i> BufferedInput<'b, 'i, &'b mut Vec<u8>> for R {
if let Some((consumed, used)) = state.change(available) {
done = true;
buf.extend_from_slice(consumed);
- used
+
+ self.consume(used);
+ read += used;
} else {
buf.extend_from_slice(available);
- available.len()
+
+ let used = available.len();
+ self.consume(used);
+ read += used;
}
}
Err(ref e) if e.kind() == io::ErrorKind::Interrupted => continue,
@@ -1152,8 +1157,6 @@ impl<'b, 'i, R: BufRead + 'i> BufferedInput<'b, 'i, &'b mut Vec<u8>> for R {
return Err(Error::Io(e));
}
};
- self.consume(used);
- read += used;
}
*position += read;
