@@ -95,8 +95,8 @@ struct LeafNode<K, V> {
95
95
96
96
/// The arrays storing the actual data of the node. Only the first `len` elements of each
97
97
/// array are initialized and valid.
98
- keys : MaybeUninit < [ K ; CAPACITY ] > ,
99
- vals : MaybeUninit < [ V ; CAPACITY ] > ,
98
+ keys : [ MaybeUninit < K > ; CAPACITY ] ,
99
+ vals : [ MaybeUninit < V > ; CAPACITY ] ,
100
100
}
101
101
102
102
impl < K , V > LeafNode < K , V > {
@@ -106,8 +106,11 @@ impl<K, V> LeafNode<K, V> {
106
106
LeafNode {
107
107
// As a general policy, we leave fields uninitialized if they can be, as this should
108
108
// be both slightly faster and easier to track in Valgrind.
109
- keys : MaybeUninit :: uninitialized ( ) ,
110
- vals : MaybeUninit :: uninitialized ( ) ,
109
+ // Creating a `[MaybeUninit; N]` array by first creating a
110
+ // `MaybeUninit<[MaybeUninit; N]>`; the `into_inner` is safe because the inner
111
+ // array does not require initialization.
112
+ keys : MaybeUninit :: uninitialized ( ) . into_inner ( ) ,
113
+ vals : MaybeUninit :: uninitialized ( ) . into_inner ( ) ,
111
114
parent : ptr:: null ( ) ,
112
115
parent_idx : MaybeUninit :: uninitialized ( ) ,
113
116
len : 0
@@ -626,7 +629,7 @@ impl<'a, K: 'a, V: 'a, Type> NodeRef<marker::Immut<'a>, K, V, Type> {
626
629
// We cannot be the root, so `as_leaf` is okay
627
630
unsafe {
628
631
slice:: from_raw_parts (
629
- self . as_leaf ( ) . vals . as_ptr ( ) as * const V ,
632
+ MaybeUninit :: first_ptr ( & self . as_leaf ( ) . vals ) ,
630
633
self . len ( )
631
634
)
632
635
}
@@ -653,7 +656,7 @@ impl<'a, K: 'a, V: 'a, Type> NodeRef<marker::Mut<'a>, K, V, Type> {
653
656
} else {
654
657
unsafe {
655
658
slice:: from_raw_parts_mut (
656
- ( * self . as_leaf_mut ( ) ) . keys . as_mut_ptr ( ) as * mut K ,
659
+ MaybeUninit :: first_mut_ptr ( & mut ( * self . as_leaf_mut ( ) ) . keys ) ,
657
660
self . len ( )
658
661
)
659
662
}
@@ -664,7 +667,7 @@ impl<'a, K: 'a, V: 'a, Type> NodeRef<marker::Mut<'a>, K, V, Type> {
664
667
debug_assert ! ( !self . is_shared_root( ) ) ;
665
668
unsafe {
666
669
slice:: from_raw_parts_mut (
667
- ( * self . as_leaf_mut ( ) ) . vals . as_mut_ptr ( ) as * mut V ,
670
+ MaybeUninit :: first_mut_ptr ( & mut ( * self . as_leaf_mut ( ) ) . vals ) ,
668
671
self . len ( )
669
672
)
670
673
}
0 commit comments