File tree Expand file tree Collapse file tree 1 file changed +6
-3
lines changed Expand file tree Collapse file tree 1 file changed +6
-3
lines changed Original file line number Diff line number Diff line change 33#[ cfg( test) ]
44mod tests;
55
6- use crate :: cmp;
76use crate :: fmt:: { self , Debug , Formatter } ;
87use crate :: io:: { Result , Write } ;
98use crate :: mem:: { self , MaybeUninit } ;
9+ use crate :: { cmp, ptr} ;
1010
1111/// A borrowed byte buffer which is incrementally filled and initialized.
1212///
@@ -250,8 +250,11 @@ impl<'a> BorrowedCursor<'a> {
250250 /// Initializes all bytes in the cursor.
251251 #[ inline]
252252 pub fn ensure_init ( & mut self ) -> & mut Self {
253- for byte in self . uninit_mut ( ) {
254- byte. write ( 0 ) ;
253+ let uninit = self . uninit_mut ( ) ;
254+ // SAFETY: 0 is a valid value for MaybeUninit<u8> and the length matches the allocation
255+ // since it is comes from a slice reference.
256+ unsafe {
257+ ptr:: write_bytes ( uninit. as_mut_ptr ( ) , 0 , uninit. len ( ) ) ;
255258 }
256259 self . buf . init = self . buf . capacity ( ) ;
257260
You can’t perform that action at this time.
0 commit comments