io::Chain: specialize some Read methods
This commit is contained in:
@@ -2389,6 +2389,39 @@ impl<T: Read, U: Read> Read for Chain<T, U> {
|
||||
}
|
||||
self.second.read_vectored(bufs)
|
||||
}
|
||||
|
||||
#[inline]
|
||||
fn is_read_vectored(&self) -> bool {
|
||||
self.first.is_read_vectored() || self.second.is_read_vectored()
|
||||
}
|
||||
|
||||
fn read_to_end(&mut self, buf: &mut Vec<u8>) -> Result<usize> {
|
||||
let mut read = 0;
|
||||
if !self.done_first {
|
||||
read += self.first.read_to_end(buf)?;
|
||||
self.done_first = true;
|
||||
}
|
||||
read += self.second.read_to_end(buf)?;
|
||||
Ok(read)
|
||||
}
|
||||
|
||||
fn read_buf(&mut self, mut buf: BorrowedCursor<'_>) -> Result<()> {
|
||||
if buf.capacity() == 0 {
|
||||
return Ok(());
|
||||
}
|
||||
|
||||
if !self.done_first {
|
||||
let old_len = buf.written();
|
||||
self.first.read_buf(buf.reborrow())?;
|
||||
|
||||
if buf.written() != old_len {
|
||||
return Ok(());
|
||||
} else {
|
||||
self.done_first = true;
|
||||
}
|
||||
}
|
||||
self.second.read_buf(buf)
|
||||
}
|
||||
}
|
||||
|
||||
#[stable(feature = "chain_bufread", since = "1.9.0")]
|
||||
|
||||
Reference in New Issue
Block a user