@@ -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,8 @@ 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
+ keys : uninitialized_array ! [ _ ; CAPACITY ] ,
110
+ vals : uninitialized_array ! [ _ ; CAPACITY ] ,
111
111
parent : ptr:: null ( ) ,
112
112
parent_idx : MaybeUninit :: uninitialized ( ) ,
113
113
len : 0
@@ -145,7 +145,7 @@ struct InternalNode<K, V> {
145
145
146
146
/// The pointers to the children of this node. `len + 1` of these are considered
147
147
/// initialized and valid.
148
- edges : [ BoxedNode < K , V > ; 2 * B ] ,
148
+ edges : [ MaybeUninit < BoxedNode < K , V > > ; 2 * B ] ,
149
149
}
150
150
151
151
impl < K , V > InternalNode < K , V > {
@@ -159,7 +159,7 @@ impl<K, V> InternalNode<K, V> {
159
159
unsafe fn new ( ) -> Self {
160
160
InternalNode {
161
161
data : LeafNode :: new ( ) ,
162
- edges : mem :: uninitialized ( )
162
+ edges : uninitialized_array ! [ _ ; 2 * B ] ,
163
163
}
164
164
}
165
165
}
@@ -261,7 +261,7 @@ impl<K, V> Root<K, V> {
261
261
-> NodeRef < marker:: Mut , K , V , marker:: Internal > {
262
262
debug_assert ! ( !self . is_shared_root( ) ) ;
263
263
let mut new_node = Box :: new ( unsafe { InternalNode :: new ( ) } ) ;
264
- new_node. edges [ 0 ] = unsafe { BoxedNode :: from_ptr ( self . node . as_ptr ( ) ) } ;
264
+ new_node. edges [ 0 ] . set ( unsafe { BoxedNode :: from_ptr ( self . node . as_ptr ( ) ) } ) ;
265
265
266
266
self . node = BoxedNode :: from_internal ( new_node) ;
267
267
self . height += 1 ;
@@ -623,7 +623,7 @@ impl<'a, K: 'a, V: 'a, Type> NodeRef<marker::Immut<'a>, K, V, Type> {
623
623
// We cannot be the root, so `as_leaf` is okay
624
624
unsafe {
625
625
slice:: from_raw_parts (
626
- self . as_leaf ( ) . vals . as_ptr ( ) as * const V ,
626
+ MaybeUninit :: first_ptr ( & self . as_leaf ( ) . vals ) ,
627
627
self . len ( )
628
628
)
629
629
}
@@ -650,7 +650,7 @@ impl<'a, K: 'a, V: 'a, Type> NodeRef<marker::Mut<'a>, K, V, Type> {
650
650
} else {
651
651
unsafe {
652
652
slice:: from_raw_parts_mut (
653
- ( * self . as_leaf_mut ( ) ) . keys . as_mut_ptr ( ) as * mut K ,
653
+ MaybeUninit :: first_ptr_mut ( & mut ( * self . as_leaf_mut ( ) ) . keys ) ,
654
654
self . len ( )
655
655
)
656
656
}
@@ -661,7 +661,7 @@ impl<'a, K: 'a, V: 'a, Type> NodeRef<marker::Mut<'a>, K, V, Type> {
661
661
debug_assert ! ( !self . is_shared_root( ) ) ;
662
662
unsafe {
663
663
slice:: from_raw_parts_mut (
664
- ( * self . as_leaf_mut ( ) ) . vals . as_mut_ptr ( ) as * mut V ,
664
+ MaybeUninit :: first_ptr_mut ( & mut ( * self . as_leaf_mut ( ) ) . vals ) ,
665
665
self . len ( )
666
666
)
667
667
}
@@ -718,7 +718,7 @@ impl<'a, K, V> NodeRef<marker::Mut<'a>, K, V, marker::Internal> {
718
718
unsafe {
719
719
ptr:: write ( self . keys_mut ( ) . get_unchecked_mut ( idx) , key) ;
720
720
ptr:: write ( self . vals_mut ( ) . get_unchecked_mut ( idx) , val) ;
721
- ptr :: write ( self . as_internal_mut ( ) . edges . get_unchecked_mut ( idx + 1 ) , edge. node ) ;
721
+ self . as_internal_mut ( ) . edges . get_unchecked_mut ( idx + 1 ) . set ( edge. node ) ;
722
722
723
723
( * self . as_leaf_mut ( ) ) . len += 1 ;
724
724
@@ -749,7 +749,7 @@ impl<'a, K, V> NodeRef<marker::Mut<'a>, K, V, marker::Internal> {
749
749
slice_insert ( self . vals_mut ( ) , 0 , val) ;
750
750
slice_insert (
751
751
slice:: from_raw_parts_mut (
752
- self . as_internal_mut ( ) . edges . as_mut_ptr ( ) ,
752
+ MaybeUninit :: first_ptr_mut ( & mut self . as_internal_mut ( ) . edges ) ,
753
753
self . len ( ) +1
754
754
) ,
755
755
0 ,
@@ -778,7 +778,9 @@ impl<'a, K, V> NodeRef<marker::Mut<'a>, K, V, marker::LeafOrInternal> {
778
778
let edge = match self . reborrow_mut ( ) . force ( ) {
779
779
ForceResult :: Leaf ( _) => None ,
780
780
ForceResult :: Internal ( internal) => {
781
- let edge = ptr:: read ( internal. as_internal ( ) . edges . get_unchecked ( idx + 1 ) ) ;
781
+ let edge = ptr:: read (
782
+ internal. as_internal ( ) . edges . get_unchecked ( idx + 1 ) . as_ptr ( )
783
+ ) ;
782
784
let mut new_root = Root { node : edge, height : internal. height - 1 } ;
783
785
( * new_root. as_mut ( ) . as_leaf_mut ( ) ) . parent = ptr:: null ( ) ;
784
786
Some ( new_root)
@@ -806,7 +808,7 @@ impl<'a, K, V> NodeRef<marker::Mut<'a>, K, V, marker::LeafOrInternal> {
806
808
ForceResult :: Internal ( mut internal) => {
807
809
let edge = slice_remove (
808
810
slice:: from_raw_parts_mut (
809
- internal. as_internal_mut ( ) . edges . as_mut_ptr ( ) ,
811
+ MaybeUninit :: first_ptr_mut ( & mut internal. as_internal_mut ( ) . edges ) ,
810
812
old_len+1
811
813
) ,
812
814
0
@@ -1085,7 +1087,7 @@ impl<'a, K, V> Handle<NodeRef<marker::Mut<'a>, K, V, marker::Internal>, marker::
1085
1087
1086
1088
slice_insert (
1087
1089
slice:: from_raw_parts_mut (
1088
- self . node . as_internal_mut ( ) . edges . as_mut_ptr ( ) ,
1090
+ MaybeUninit :: first_ptr_mut ( & mut self . node . as_internal_mut ( ) . edges ) ,
1089
1091
self . node . len ( )
1090
1092
) ,
1091
1093
self . idx + 1 ,
@@ -1140,7 +1142,9 @@ impl<BorrowType, K, V>
1140
1142
pub fn descend ( self ) -> NodeRef < BorrowType , K , V , marker:: LeafOrInternal > {
1141
1143
NodeRef {
1142
1144
height : self . node . height - 1 ,
1143
- node : unsafe { self . node . as_internal ( ) . edges . get_unchecked ( self . idx ) . as_ptr ( ) } ,
1145
+ node : unsafe {
1146
+ self . node . as_internal ( ) . edges . get_unchecked ( self . idx ) . get_ref ( ) . as_ptr ( )
1147
+ } ,
1144
1148
root : self . node . root ,
1145
1149
_marker : PhantomData
1146
1150
}
0 commit comments