@@ -95,8 +95,8 @@ struct LeafNode<K, V> {
9595
9696 /// The arrays storing the actual data of the node. Only the first `len` elements of each
9797 /// 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 ] ,
100100}
101101
102102impl < K , V > LeafNode < K , V > {
@@ -106,8 +106,8 @@ impl<K, V> LeafNode<K, V> {
106106 LeafNode {
107107 // As a general policy, we leave fields uninitialized if they can be, as this should
108108 // 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 ] ,
111111 parent : ptr:: null ( ) ,
112112 parent_idx : MaybeUninit :: uninitialized ( ) ,
113113 len : 0
@@ -145,7 +145,7 @@ struct InternalNode<K, V> {
145145
146146 /// The pointers to the children of this node. `len + 1` of these are considered
147147 /// initialized and valid.
148- edges : [ BoxedNode < K , V > ; 2 * B ] ,
148+ edges : [ MaybeUninit < BoxedNode < K , V > > ; 2 * B ] ,
149149}
150150
151151impl < K , V > InternalNode < K , V > {
@@ -159,7 +159,7 @@ impl<K, V> InternalNode<K, V> {
159159 unsafe fn new ( ) -> Self {
160160 InternalNode {
161161 data : LeafNode :: new ( ) ,
162- edges : mem :: uninitialized ( )
162+ edges : uninitialized_array ! [ _ ; 2 * B ] ,
163163 }
164164 }
165165}
@@ -261,7 +261,7 @@ impl<K, V> Root<K, V> {
261261 -> NodeRef < marker:: Mut , K , V , marker:: Internal > {
262262 debug_assert ! ( !self . is_shared_root( ) ) ;
263263 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 ( ) ) } ) ;
265265
266266 self . node = BoxedNode :: from_internal ( new_node) ;
267267 self . height += 1 ;
@@ -623,7 +623,7 @@ impl<'a, K: 'a, V: 'a, Type> NodeRef<marker::Immut<'a>, K, V, Type> {
623623 // We cannot be the root, so `as_leaf` is okay
624624 unsafe {
625625 slice:: from_raw_parts (
626- self . as_leaf ( ) . vals . as_ptr ( ) as * const V ,
626+ MaybeUninit :: first_ptr ( & self . as_leaf ( ) . vals ) ,
627627 self . len ( )
628628 )
629629 }
@@ -650,7 +650,7 @@ impl<'a, K: 'a, V: 'a, Type> NodeRef<marker::Mut<'a>, K, V, Type> {
650650 } else {
651651 unsafe {
652652 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 ) ,
654654 self . len ( )
655655 )
656656 }
@@ -661,7 +661,7 @@ impl<'a, K: 'a, V: 'a, Type> NodeRef<marker::Mut<'a>, K, V, Type> {
661661 debug_assert ! ( !self . is_shared_root( ) ) ;
662662 unsafe {
663663 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 ) ,
665665 self . len ( )
666666 )
667667 }
@@ -718,7 +718,7 @@ impl<'a, K, V> NodeRef<marker::Mut<'a>, K, V, marker::Internal> {
718718 unsafe {
719719 ptr:: write ( self . keys_mut ( ) . get_unchecked_mut ( idx) , key) ;
720720 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 ) ;
722722
723723 ( * self . as_leaf_mut ( ) ) . len += 1 ;
724724
@@ -749,7 +749,7 @@ impl<'a, K, V> NodeRef<marker::Mut<'a>, K, V, marker::Internal> {
749749 slice_insert ( self . vals_mut ( ) , 0 , val) ;
750750 slice_insert (
751751 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 ) ,
753753 self . len ( ) +1
754754 ) ,
755755 0 ,
@@ -778,7 +778,9 @@ impl<'a, K, V> NodeRef<marker::Mut<'a>, K, V, marker::LeafOrInternal> {
778778 let edge = match self . reborrow_mut ( ) . force ( ) {
779779 ForceResult :: Leaf ( _) => None ,
780780 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+ ) ;
782784 let mut new_root = Root { node : edge, height : internal. height - 1 } ;
783785 ( * new_root. as_mut ( ) . as_leaf_mut ( ) ) . parent = ptr:: null ( ) ;
784786 Some ( new_root)
@@ -806,7 +808,7 @@ impl<'a, K, V> NodeRef<marker::Mut<'a>, K, V, marker::LeafOrInternal> {
806808 ForceResult :: Internal ( mut internal) => {
807809 let edge = slice_remove (
808810 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 ) ,
810812 old_len+1
811813 ) ,
812814 0
@@ -1085,7 +1087,7 @@ impl<'a, K, V> Handle<NodeRef<marker::Mut<'a>, K, V, marker::Internal>, marker::
10851087
10861088 slice_insert (
10871089 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 ) ,
10891091 self . node . len ( )
10901092 ) ,
10911093 self . idx + 1 ,
@@ -1140,7 +1142,9 @@ impl<BorrowType, K, V>
11401142 pub fn descend ( self ) -> NodeRef < BorrowType , K , V , marker:: LeafOrInternal > {
11411143 NodeRef {
11421144 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+ } ,
11441148 root : self . node . root ,
11451149 _marker : PhantomData
11461150 }
0 commit comments