File tree 1 file changed +6
-3
lines changed
1 file changed +6
-3
lines changed Original file line number Diff line number Diff line change 3
3
#[ cfg( test) ]
4
4
mod tests;
5
5
6
- use crate :: cmp;
7
6
use crate :: fmt:: { self , Debug , Formatter } ;
8
7
use crate :: io:: { Result , Write } ;
9
8
use crate :: mem:: { self , MaybeUninit } ;
9
+ use crate :: { cmp, ptr} ;
10
10
11
11
/// A borrowed byte buffer which is incrementally filled and initialized.
12
12
///
@@ -250,8 +250,11 @@ impl<'a> BorrowedCursor<'a> {
250
250
/// Initializes all bytes in the cursor.
251
251
#[ inline]
252
252
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 ( ) ) ;
255
258
}
256
259
self . buf . init = self . buf . capacity ( ) ;
257
260
You can’t perform that action at this time.
0 commit comments