[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
This commit is contained in:
parent
d8d8dac273
commit
034f8bb438
2 changed files with 0 additions and 54 deletions
|
|
@ -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,
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue