@@ -744,31 +744,17 @@ impl BootServices {
744
744
// Determine how much we need to allocate.
745
745
let ( status1, buffer_size) = self . locate_handle ( search_type, None ) ?. split ( ) ;
746
746
747
- // Allocate a large enough buffer.
748
- let mut buffer = Vec :: new ( ) ;
749
- buffer. resize_with ( buffer_size , MaybeUninit :: uninit ) ;
747
+ // Allocate a large enough buffer without pointless initialization .
748
+ let mut handles = Vec :: with_capacity ( buffer_size ) ;
749
+ let buffer = handles . spare_capacity_mut ( ) ;
750
750
751
751
// Perform the search.
752
- let ( status2, buffer_size) = self . locate_handle ( search_type, Some ( & mut buffer) ) ?. split ( ) ;
753
-
754
- // Ensure that the buffer's length matches the number of handles
755
- // that were actually filled in. Calling `truncate` only has an
756
- // effect if the new length is smaller than the vec's currently
757
- // length, and that is sufficient here since if `buffer` is
758
- // smaller than the amount of data `locate_handle` wants to
759
- // return then `find_handles` will end up returning
760
- // `Status::BUFFER_TOO_SMALL` and `buffer` will be dropped.
761
- buffer. truncate ( buffer_size) ;
762
-
763
- // Convert the buffer from MaybeUninits to Handles.
764
- // The raw parts roundtrip with a pointer cast is better than just
765
- // transmuting vectors per mem::transmute docs.
766
- // Transmuting MaybeUninit<T> to T is also correct, if we are sure that
767
- // it is initialized, which it is, unless UEFI is broken
768
- let handles = unsafe {
769
- let ( ptr, len, cap) = buffer. into_raw_parts ( ) ;
770
- Vec :: from_raw_parts ( ptr as * mut Handle , len, cap)
771
- } ;
752
+ let ( status2, buffer_size) = self . locate_handle ( search_type, Some ( buffer) ) ?. split ( ) ;
753
+
754
+ // Mark the returned number of elements as initialized.
755
+ unsafe {
756
+ handles. set_len ( buffer_size) ;
757
+ }
772
758
773
759
// Emit output, with warnings
774
760
status1
0 commit comments