File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 11#![ feature( test) ]
2+ #![ feature( maybe_uninit_as_bytes) ]
3+
24extern crate test;
35
46use std:: mem:: MaybeUninit ;
@@ -21,16 +23,9 @@ fn bench_getrandom<const N: usize>(b: &mut test::Bencher) {
2123fn bench_getrandom_uninit < const N : usize > ( b : & mut test:: Bencher ) {
2224 b. bytes = N as u64 ;
2325 b. iter ( || {
24- // TODO: When the feature `maybe_uninit_as_bytes` is available, use:
25- // ```
26- // let mut buf: MaybeUninit<[u8; N]> = MaybeUninit::uninit();
27- // getrandom::getrandom_uninit(buf.as_bytes_mut()).unwrap();
28- // test::black_box(unsafe { buf.assume_init() })
29- // ```
30- // since that is the shape we expect most callers to have.
31- let mut buf = [ MaybeUninit :: new ( 0u8 ) ; N ] ;
32- let buf = getrandom:: getrandom_uninit ( & mut buf[ ..] ) . unwrap ( ) ;
33- test:: black_box ( & buf) ;
26+ let mut buf: MaybeUninit < [ u8 ; N ] > = MaybeUninit :: uninit ( ) ;
27+ let buf = getrandom:: getrandom_uninit ( buf. as_bytes_mut ( ) ) . unwrap ( ) ;
28+ test:: black_box ( buf) ;
3429 } ) ;
3530}
3631
You can’t perform that action at this time.
0 commit comments