From 034f8bb438765f5cfbdf76bc1612c22e867bb462 Mon Sep 17 00:00:00 2001 From: The 8472 Date: Sun, 12 Nov 2023 19:59:22 +0100 Subject: [PATCH] [beta] remove specialization that caused perf regression the fix on nightly is recent and should get time to bake, removal of the optimization is the less risky approach for a backport --- library/std/src/io/copy.rs | 42 -------------------------------- library/std/src/io/copy/tests.rs | 12 --------- 2 files changed, 54 deletions(-) diff --git a/library/std/src/io/copy.rs b/library/std/src/io/copy.rs index 57d226a3771e..eafd078a7290 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 BufferedWriterSpec for BufWriter { } } -impl BufferedWriterSpec for Vec { - fn buffer_size(&self) -> usize { - cmp::max(DEFAULT_BUF_SIZE, self.capacity() - self.len()) - } - - fn copy_from(&mut self, reader: &mut R) -> Result { - 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( 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 af137eaf856f..d9998e87c66d 100644 --- a/library/std/src/io/copy/tests.rs +++ b/library/std/src/io/copy/tests.rs @@ -80,18 +80,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);