diff options
| author | Benoît du Garreau <bdgdlm@outlook.com> | 2022-12-19 20:16:49 +0100 |
|---|---|---|
| committer | Benoît du Garreau <bdgdlm@outlook.com> | 2023-07-26 23:28:47 +0200 |
| commit | cada71e3f4a0bcd2886b278523dd07eeff2e3e8e (patch) | |
| tree | 21aa1627235c1550f960d0d3e94e1ec21030e1d2 | |
| parent | 4653c93e4442d88bf3278067183c8fdc0be74a1f (diff) | |
`io::Chain`: specialize some `Read` methods
| -rw-r--r-- | library/std/src/io/mod.rs | 33 |
1 files changed, 33 insertions, 0 deletions
diff --git a/library/std/src/io/mod.rs b/library/std/src/io/mod.rs index 23a13523fc2..23159459a70 100644 --- a/library/std/src/io/mod.rs +++ b/library/std/src/io/mod.rs @@ -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")] |
