Skip to content

Commit 034f8bb

Browse files
committed
[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
1 parent d8d8dac commit 034f8bb

File tree

2 files changed

+0
-54
lines changed

2 files changed

+0
-54
lines changed

library/std/src/io/copy.rs

Lines changed: 0 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
use super::{BorrowedBuf, BufReader, BufWriter, Read, Result, Write, DEFAULT_BUF_SIZE};
22
use crate::alloc::Allocator;
3-
use crate::cmp;
43
use crate::collections::VecDeque;
54
use crate::io::IoSlice;
65
use crate::mem::MaybeUninit;
@@ -255,47 +254,6 @@ impl<I: Write + ?Sized> BufferedWriterSpec for BufWriter<I> {
255254
}
256255
}
257256

258-
impl<A: Allocator> BufferedWriterSpec for Vec<u8, A> {
259-
fn buffer_size(&self) -> usize {
260-
cmp::max(DEFAULT_BUF_SIZE, self.capacity() - self.len())
261-
}
262-
263-
fn copy_from<R: Read + ?Sized>(&mut self, reader: &mut R) -> Result<u64> {
264-
let mut bytes = 0;
265-
266-
// avoid allocating before we have determined that there's anything to read
267-
if self.capacity() == 0 {
268-
bytes = stack_buffer_copy(&mut reader.take(DEFAULT_BUF_SIZE as u64), self)?;
269-
if bytes == 0 {
270-
return Ok(0);
271-
}
272-
}
273-
274-
loop {
275-
self.reserve(DEFAULT_BUF_SIZE);
276-
let mut buf: BorrowedBuf<'_> = self.spare_capacity_mut().into();
277-
match reader.read_buf(buf.unfilled()) {
278-
Ok(()) => {}
279-
Err(e) if e.is_interrupted() => continue,
280-
Err(e) => return Err(e),
281-
};
282-
283-
let read = buf.filled().len();
284-
if read == 0 {
285-
break;
286-
}
287-
288-
// SAFETY: BorrowedBuf guarantees all of its filled bytes are init
289-
// and the number of read bytes can't exceed the spare capacity since
290-
// that's what the buffer is borrowing from.
291-
unsafe { self.set_len(self.len() + read) };
292-
bytes += read as u64;
293-
}
294-
295-
Ok(bytes)
296-
}
297-
}
298-
299257
fn stack_buffer_copy<R: Read + ?Sized, W: Write + ?Sized>(
300258
reader: &mut R,
301259
writer: &mut W,

library/std/src/io/copy/tests.rs

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -80,18 +80,6 @@ fn copy_specializes_bufreader() {
8080
);
8181
}
8282

83-
#[test]
84-
fn copy_specializes_to_vec() {
85-
let cap = 123456;
86-
let mut source = ShortReader { cap, observed_buffer: 0, read_size: 1337 };
87-
let mut sink = Vec::new();
88-
assert_eq!(cap as u64, io::copy(&mut source, &mut sink).unwrap());
89-
assert!(
90-
source.observed_buffer > DEFAULT_BUF_SIZE,
91-
"expected a large buffer to be provided to the reader"
92-
);
93-
}
94-
9583
#[test]
9684
fn copy_specializes_from_vecdeque() {
9785
let mut source = VecDeque::with_capacity(100 * 1024);

0 commit comments

Comments
 (0)