@@ -112,20 +112,8 @@ impl<K, V> InternalNode<K, V> {
112
112
///
113
113
/// However, `BoxedNode` contains no information as to which of the two types
114
114
/// of nodes it actually contains, and, partially due to this lack of information,
115
- /// has no destructor.
116
- struct BoxedNode < K , V > {
117
- ptr : NonNull < LeafNode < K , V > > ,
118
- }
119
-
120
- impl < K , V > BoxedNode < K , V > {
121
- fn from_owned ( ptr : NonNull < LeafNode < K , V > > ) -> Self {
122
- BoxedNode { ptr }
123
- }
124
-
125
- fn as_ptr ( & self ) -> NonNull < LeafNode < K , V > > {
126
- self . ptr
127
- }
128
- }
115
+ /// is not a separate type and has no destructor.
116
+ type BoxedNode < K , V > = NonNull < LeafNode < K , V > > ;
129
117
130
118
/// An owned tree.
131
119
///
@@ -168,11 +156,6 @@ impl<K, V, Type> NodeRef<marker::Owned, K, V, Type> {
168
156
pub fn borrow_valmut ( & mut self ) -> NodeRef < marker:: ValMut < ' _ > , K , V , Type > {
169
157
NodeRef { height : self . height , node : self . node , _marker : PhantomData }
170
158
}
171
-
172
- /// Packs the reference, aware of type and height, into a type-agnostic pointer.
173
- fn into_boxed_node ( self ) -> BoxedNode < K , V > {
174
- BoxedNode :: from_owned ( self . node )
175
- }
176
159
}
177
160
178
161
impl < K , V > NodeRef < marker:: Owned , K , V , marker:: LeafOrInternal > {
@@ -181,7 +164,7 @@ impl<K, V> NodeRef<marker::Owned, K, V, marker::LeafOrInternal> {
181
164
/// and is the opposite of `pop_internal_level`.
182
165
pub fn push_internal_level ( & mut self ) -> NodeRef < marker:: Mut < ' _ > , K , V , marker:: Internal > {
183
166
let mut new_node = Box :: new ( unsafe { InternalNode :: new ( ) } ) ;
184
- new_node. edges [ 0 ] . write ( BoxedNode :: from_owned ( self . node ) ) ;
167
+ new_node. edges [ 0 ] . write ( self . node ) ;
185
168
let mut new_root = NodeRef :: from_new_internal ( new_node, self . height + 1 ) ;
186
169
new_root. borrow_mut ( ) . first_edge ( ) . correct_parent_link ( ) ;
187
170
* self = new_root. forget_type ( ) ;
@@ -288,13 +271,6 @@ unsafe impl<'a, K: Send + 'a, V: Send + 'a, Type> Send for NodeRef<marker::Mut<'
288
271
unsafe impl < ' a , K : Send + ' a , V : Send + ' a , Type > Send for NodeRef < marker:: ValMut < ' a > , K , V , Type > { }
289
272
unsafe impl < K : Send , V : Send , Type > Send for NodeRef < marker:: Owned , K , V , Type > { }
290
273
291
- impl < BorrowType , K , V > NodeRef < BorrowType , K , V , marker:: LeafOrInternal > {
292
- /// Unpack a node reference that was packed by `Root::into_boxed_node`.
293
- fn from_boxed_node ( boxed_node : BoxedNode < K , V > , height : usize ) -> Self {
294
- NodeRef { height, node : boxed_node. as_ptr ( ) , _marker : PhantomData }
295
- }
296
- }
297
-
298
274
impl < BorrowType , K , V > NodeRef < BorrowType , K , V , marker:: Internal > {
299
275
/// Unpack a node reference that was packed as `NodeRef::parent`.
300
276
fn from_internal ( node : NonNull < InternalNode < K , V > > , height : usize ) -> Self {
@@ -695,7 +671,7 @@ impl<'a, K: 'a, V: 'a> NodeRef<marker::Mut<'a>, K, V, marker::Internal> {
695
671
unsafe {
696
672
self . reborrow_mut ( ) . into_key_area_mut_at ( idx) . write ( key) ;
697
673
self . reborrow_mut ( ) . into_val_area_mut_at ( idx) . write ( val) ;
698
- self . reborrow_mut ( ) . into_edge_area_mut_at ( idx + 1 ) . write ( edge. into_boxed_node ( ) ) ;
674
+ self . reborrow_mut ( ) . into_edge_area_mut_at ( idx + 1 ) . write ( edge. node ) ;
699
675
Handle :: new_edge ( self . reborrow_mut ( ) , idx + 1 ) . correct_parent_link ( ) ;
700
676
}
701
677
}
@@ -710,7 +686,7 @@ impl<'a, K: 'a, V: 'a> NodeRef<marker::Mut<'a>, K, V, marker::Internal> {
710
686
* self . reborrow_mut ( ) . into_len_mut ( ) += 1 ;
711
687
slice_insert ( self . reborrow_mut ( ) . into_key_area_slice ( ) , 0 , key) ;
712
688
slice_insert ( self . reborrow_mut ( ) . into_val_area_slice ( ) , 0 , val) ;
713
- slice_insert ( self . reborrow_mut ( ) . into_edge_area_slice ( ) , 0 , edge. into_boxed_node ( ) ) ;
689
+ slice_insert ( self . reborrow_mut ( ) . into_edge_area_slice ( ) , 0 , edge. node ) ;
714
690
}
715
691
716
692
self . correct_all_childrens_parent_links ( ) ;
@@ -732,8 +708,8 @@ impl<'a, K: 'a, V: 'a> NodeRef<marker::Mut<'a>, K, V, marker::LeafOrInternal> {
732
708
let edge = match self . reborrow_mut ( ) . force ( ) {
733
709
ForceResult :: Leaf ( _) => None ,
734
710
ForceResult :: Internal ( internal) => {
735
- let boxed_node = ptr:: read ( internal. reborrow ( ) . edge_at ( idx + 1 ) ) ;
736
- let mut edge = Root :: from_boxed_node ( boxed_node , internal. height - 1 ) ;
711
+ let node = ptr:: read ( internal. reborrow ( ) . edge_at ( idx + 1 ) ) ;
712
+ let mut edge = Root { node , height : internal. height - 1 , _marker : PhantomData } ;
737
713
// In practice, clearing the parent is a waste of time, because we will
738
714
// insert the node elsewhere and set its parent link again.
739
715
edge. borrow_mut ( ) . clear_parent_link ( ) ;
@@ -760,9 +736,8 @@ impl<'a, K: 'a, V: 'a> NodeRef<marker::Mut<'a>, K, V, marker::LeafOrInternal> {
760
736
let edge = match self . reborrow_mut ( ) . force ( ) {
761
737
ForceResult :: Leaf ( _) => None ,
762
738
ForceResult :: Internal ( mut internal) => {
763
- let boxed_node =
764
- slice_remove ( internal. reborrow_mut ( ) . into_edge_area_slice ( ) , 0 ) ;
765
- let mut edge = Root :: from_boxed_node ( boxed_node, internal. height - 1 ) ;
739
+ let node = slice_remove ( internal. reborrow_mut ( ) . into_edge_area_slice ( ) , 0 ) ;
740
+ let mut edge = Root { node, height : internal. height - 1 , _marker : PhantomData } ;
766
741
// In practice, clearing the parent is a waste of time, because we will
767
742
// insert the node elsewhere and set its parent link again.
768
743
edge. borrow_mut ( ) . clear_parent_link ( ) ;
@@ -1041,12 +1016,11 @@ impl<'a, K: 'a, V: 'a> Handle<NodeRef<marker::Mut<'a>, K, V, marker::Internal>,
1041
1016
debug_assert ! ( self . node. len( ) < CAPACITY ) ;
1042
1017
debug_assert ! ( edge. height == self . node. height - 1 ) ;
1043
1018
1044
- let boxed_node = edge. into_boxed_node ( ) ;
1045
1019
unsafe {
1046
1020
* self . node . reborrow_mut ( ) . into_len_mut ( ) += 1 ;
1047
1021
slice_insert ( self . node . reborrow_mut ( ) . into_key_area_slice ( ) , self . idx , key) ;
1048
1022
slice_insert ( self . node . reborrow_mut ( ) . into_val_area_slice ( ) , self . idx , val) ;
1049
- slice_insert ( self . node . reborrow_mut ( ) . into_edge_area_slice ( ) , self . idx + 1 , boxed_node ) ;
1023
+ slice_insert ( self . node . reborrow_mut ( ) . into_edge_area_slice ( ) , self . idx + 1 , edge . node ) ;
1050
1024
1051
1025
self . node . correct_childrens_parent_links ( ( self . idx + 1 ) ..=self . node . len ( ) ) ;
1052
1026
}
@@ -1135,8 +1109,8 @@ impl<BorrowType, K, V> Handle<NodeRef<BorrowType, K, V, marker::Internal>, marke
1135
1109
// reference (Rust issue #73987) and invalidate any other references
1136
1110
// to or inside the array, should any be around.
1137
1111
let parent_ptr = NodeRef :: as_internal_ptr ( & self . node ) ;
1138
- let boxed_node = unsafe { ( * parent_ptr) . edges . get_unchecked ( self . idx ) . assume_init_read ( ) } ;
1139
- NodeRef :: from_boxed_node ( boxed_node , self . node . height - 1 )
1112
+ let node = unsafe { ( * parent_ptr) . edges . get_unchecked ( self . idx ) . assume_init_read ( ) } ;
1113
+ NodeRef { node , height : self . node . height - 1 , _marker : PhantomData }
1140
1114
}
1141
1115
}
1142
1116
0 commit comments