File tree Expand file tree Collapse file tree 1 file changed +8
-1
lines changed Expand file tree Collapse file tree 1 file changed +8
-1
lines changed Original file line number Diff line number Diff line change @@ -83,21 +83,28 @@ impl<I: Write> BufferedCopySpec for BufWriter<I> {
8383 }
8484
8585 let mut len = 0 ;
86+ let mut init = 0 ;
8687
8788 loop {
8889 let buf = writer. buffer_mut ( ) ;
8990 let mut read_buf = ReadBuf :: uninit ( buf. spare_capacity_mut ( ) ) ;
9091
92+ // SAFETY: init is either 0 or the initialized_len of the previous iteration
93+ unsafe {
94+ read_buf. assume_init ( init) ;
95+ }
96+
9197 if read_buf. capacity ( ) >= DEFAULT_BUF_SIZE {
9298 match reader. read_buf ( & mut read_buf) {
93- //Ok(0) => return Ok(len), // EOF reached
9499 Ok ( ( ) ) => {
95100 let bytes_read = read_buf. filled_len ( ) ;
96101
97102 if bytes_read == 0 {
98103 return Ok ( len) ;
99104 }
100105
106+ init = read_buf. initialized_len ( ) ;
107+
101108 // SAFETY: ReadBuf guarantees all of its filled bytes are init
102109 unsafe { buf. set_len ( buf. len ( ) + bytes_read) } ;
103110 len += bytes_read as u64 ;
You can’t perform that action at this time.
0 commit comments