diff options
| author | bors <bors@rust-lang.org> | 2023-11-13 04:09:18 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2023-11-13 04:09:18 +0000 |
| commit | 79e9716c980570bfd1f666e3b16ac583f0168962 (patch) | |
| tree | 3af567c0e202f9b3b28963ef565669d164e71345 /library/std | |
| parent | 22d4a4ff135fd79c06cf0274754bd571b1fff400 (diff) | |
| parent | 7e1d1d4b220f226fdea3ce57e3604e167aa28aae (diff) | |
| download | rust-1.74.0.tar.gz rust-1.74.0.zip | |
Auto merge of #117843 - Mark-Simulacrum:stable-next, r=Mark-Simulacrum 1.74.0
[stable] Prepare 1.74.0 release https://forge.rust-lang.org/release/process.html#promote-branches-t-3-days-monday Also backports: * Disabling specialization as an alternative backport of "Fix excessive initialization and reads beyond EOF in io::copy(_, Vec<u8>) specialization #117576" * coverage: Avoid creating malformed macro name spans #117827 r? `@Mark-Simulacrum`
Diffstat (limited to 'library/std')
| -rw-r--r-- | library/std/src/io/copy.rs | 42 | ||||
| -rw-r--r-- | library/std/src/io/copy/tests.rs | 12 |
2 files changed, 0 insertions, 54 deletions
diff --git a/library/std/src/io/copy.rs b/library/std/src/io/copy.rs index 57d226a3771..eafd078a729 100644 --- a/library/std/src/io/copy.rs +++ b/library/std/src/io/copy.rs @@ -1,6 +1,5 @@ use super::{BorrowedBuf, BufReader, BufWriter, Read, Result, Write, DEFAULT_BUF_SIZE}; use crate::alloc::Allocator; -use crate::cmp; use crate::collections::VecDeque; use crate::io::IoSlice; use crate::mem::MaybeUninit; @@ -255,47 +254,6 @@ impl<I: Write + ?Sized> BufferedWriterSpec for BufWriter<I> { } } -impl<A: Allocator> BufferedWriterSpec for Vec<u8, A> { - fn buffer_size(&self) -> usize { - cmp::max(DEFAULT_BUF_SIZE, self.capacity() - self.len()) - } - - fn copy_from<R: Read + ?Sized>(&mut self, reader: &mut R) -> Result<u64> { - let mut bytes = 0; - - // avoid allocating before we have determined that there's anything to read - if self.capacity() == 0 { - bytes = stack_buffer_copy(&mut reader.take(DEFAULT_BUF_SIZE as u64), self)?; - if bytes == 0 { - return Ok(0); - } - } - - loop { - self.reserve(DEFAULT_BUF_SIZE); - let mut buf: BorrowedBuf<'_> = self.spare_capacity_mut().into(); - match reader.read_buf(buf.unfilled()) { - Ok(()) => {} - Err(e) if e.is_interrupted() => continue, - Err(e) => return Err(e), - }; - - let read = buf.filled().len(); - if read == 0 { - break; - } - - // SAFETY: BorrowedBuf guarantees all of its filled bytes are init - // and the number of read bytes can't exceed the spare capacity since - // that's what the buffer is borrowing from. - unsafe { self.set_len(self.len() + read) }; - bytes += read as u64; - } - - Ok(bytes) - } -} - fn stack_buffer_copy<R: Read + ?Sized, W: Write + ?Sized>( reader: &mut R, writer: &mut W, diff --git a/library/std/src/io/copy/tests.rs b/library/std/src/io/copy/tests.rs index af137eaf856..d9998e87c66 100644 --- a/library/std/src/io/copy/tests.rs +++ b/library/std/src/io/copy/tests.rs @@ -81,18 +81,6 @@ fn copy_specializes_bufreader() { } #[test] -fn copy_specializes_to_vec() { - let cap = 123456; - let mut source = ShortReader { cap, observed_buffer: 0, read_size: 1337 }; - let mut sink = Vec::new(); - assert_eq!(cap as u64, io::copy(&mut source, &mut sink).unwrap()); - assert!( - source.observed_buffer > DEFAULT_BUF_SIZE, - "expected a large buffer to be provided to the reader" - ); -} - -#[test] fn copy_specializes_from_vecdeque() { let mut source = VecDeque::with_capacity(100 * 1024); for _ in 0..20 * 1024 { |
