mirror of
https://github.com/rust-lang/rust.git
synced 2025-02-17 09:23:05 +00:00
Don't reinitialize here
This commit is contained in:
parent
5a97090b04
commit
f92241d251
@ -83,14 +83,19 @@ impl<I: Write> BufferedCopySpec for BufWriter<I> {
|
||||
}
|
||||
|
||||
let mut len = 0;
|
||||
let mut init = 0;
|
||||
|
||||
loop {
|
||||
let buf = writer.buffer_mut();
|
||||
let mut read_buf = ReadBuf::uninit(buf.spare_capacity_mut());
|
||||
|
||||
// SAFETY: init is either 0 or the initialized_len of the previous iteration
|
||||
unsafe {
|
||||
read_buf.assume_init(init);
|
||||
}
|
||||
|
||||
if read_buf.capacity() >= DEFAULT_BUF_SIZE {
|
||||
match reader.read_buf(&mut read_buf) {
|
||||
//Ok(0) => return Ok(len), // EOF reached
|
||||
Ok(()) => {
|
||||
let bytes_read = read_buf.filled_len();
|
||||
|
||||
@ -98,6 +103,8 @@ impl<I: Write> BufferedCopySpec for BufWriter<I> {
|
||||
return Ok(len);
|
||||
}
|
||||
|
||||
init = read_buf.initialized_len();
|
||||
|
||||
// SAFETY: ReadBuf guarantees all of its filled bytes are init
|
||||
unsafe { buf.set_len(buf.len() + bytes_read) };
|
||||
len += bytes_read as u64;
|
||||
|
Loading…
Reference in New Issue
Block a user