File tree 2 files changed +10
-18
lines changed
2 files changed +10
-18
lines changed Original file line number Diff line number Diff line change @@ -182,35 +182,26 @@ pub const fn repeat(byte: u8) -> Repeat {
182
182
impl Read for Repeat {
183
183
#[ inline]
184
184
fn read ( & mut self , buf : & mut [ u8 ] ) -> io:: Result < usize > {
185
- for slot in & mut * buf {
186
- * slot = self . byte ;
187
- }
185
+ buf. fill ( self . byte ) ;
188
186
Ok ( buf. len ( ) )
189
187
}
190
188
189
+ #[ inline]
191
190
fn read_exact ( & mut self , buf : & mut [ u8 ] ) -> io:: Result < ( ) > {
192
- for slot in & mut * buf {
193
- * slot = self . byte ;
194
- }
191
+ buf. fill ( self . byte ) ;
195
192
Ok ( ( ) )
196
193
}
197
194
195
+ #[ inline]
198
196
fn read_buf ( & mut self , mut buf : BorrowedCursor < ' _ > ) -> io:: Result < ( ) > {
199
- // SAFETY: No uninit bytes are being written
200
- for slot in unsafe { buf. as_mut ( ) } {
201
- slot. write ( self . byte ) ;
202
- }
203
-
204
- let remaining = buf. capacity ( ) ;
205
-
206
- // SAFETY: the entire unfilled portion of buf has been initialized
207
- unsafe {
208
- buf. advance_unchecked ( remaining) ;
209
- }
210
-
197
+ // SAFETY: No uninit bytes are being written.
198
+ crate :: mem:: MaybeUninit :: fill ( unsafe { buf. as_mut ( ) } , self . byte ) ;
199
+ // SAFETY: the entire unfilled portion of buf has been initialized.
200
+ unsafe { buf. advance_unchecked ( buf. capacity ( ) ) } ;
211
201
Ok ( ( ) )
212
202
}
213
203
204
+ #[ inline]
214
205
fn read_buf_exact ( & mut self , buf : BorrowedCursor < ' _ > ) -> io:: Result < ( ) > {
215
206
self . read_buf ( buf)
216
207
}
Original file line number Diff line number Diff line change 302
302
#![ feature( link_cfg) ]
303
303
#![ feature( linkage) ]
304
304
#![ feature( macro_metavar_expr_concat) ]
305
+ #![ feature( maybe_uninit_fill) ]
305
306
#![ feature( min_specialization) ]
306
307
#![ feature( must_not_suspend) ]
307
308
#![ feature( needs_panic_runtime) ]
You can’t perform that action at this time.
0 commit comments