@@ -307,7 +307,7 @@ impl<K, V> Root<K, V> {
307
307
. node )
308
308
} ;
309
309
self . height -= 1 ;
310
- self . as_mut ( ) . as_leaf_mut ( ) . parent = ptr:: null ( ) ;
310
+ unsafe { ( * self . as_mut ( ) . as_leaf_mut ( ) ) . parent = ptr:: null ( ) ; }
311
311
312
312
unsafe {
313
313
Global . dealloc ( NonNull :: from ( top) . cast ( ) , Layout :: new :: < InternalNode < K , V > > ( ) ) ;
@@ -570,9 +570,10 @@ impl<'a, K, V, Type> NodeRef<marker::Mut<'a>, K, V, Type> {
570
570
}
571
571
}
572
572
573
- fn as_leaf_mut ( & mut self ) -> & mut LeafNode < K , V > {
574
- // We are mutable, so we cannot be the root, so this is okay.
575
- unsafe { self . node . as_mut ( ) }
573
+ /// Returns a raw ptr to avoid asserting exclusive access to the entire node.
574
+ fn as_leaf_mut ( & mut self ) -> * mut LeafNode < K , V > {
575
+ // We are mutable, so we cannot be the root, so accessing this as a leaf is okay.
576
+ self . node . as_ptr ( )
576
577
}
577
578
578
579
fn keys_mut ( & mut self ) -> & mut [ K ] {
@@ -659,7 +660,7 @@ impl<'a, K: 'a, V: 'a, Type> NodeRef<marker::Mut<'a>, K, V, Type> {
659
660
} else {
660
661
unsafe {
661
662
slice:: from_raw_parts_mut (
662
- self . as_leaf_mut ( ) . keys . as_mut_ptr ( ) as * mut K ,
663
+ ( * self . as_leaf_mut ( ) ) . keys . as_mut_ptr ( ) as * mut K ,
663
664
self . len ( )
664
665
)
665
666
}
@@ -670,7 +671,7 @@ impl<'a, K: 'a, V: 'a, Type> NodeRef<marker::Mut<'a>, K, V, Type> {
670
671
debug_assert ! ( !self . is_shared_root( ) ) ;
671
672
unsafe {
672
673
slice:: from_raw_parts_mut (
673
- self . as_leaf_mut ( ) . vals . as_mut_ptr ( ) as * mut V ,
674
+ ( * self . as_leaf_mut ( ) ) . vals . as_mut_ptr ( ) as * mut V ,
674
675
self . len ( )
675
676
)
676
677
}
@@ -694,9 +695,9 @@ impl<'a, K, V> NodeRef<marker::Mut<'a>, K, V, marker::Leaf> {
694
695
unsafe {
695
696
ptr:: write ( self . keys_mut ( ) . get_unchecked_mut ( idx) , key) ;
696
697
ptr:: write ( self . vals_mut ( ) . get_unchecked_mut ( idx) , val) ;
697
- }
698
698
699
- self . as_leaf_mut ( ) . len += 1 ;
699
+ ( * self . as_leaf_mut ( ) ) . len += 1 ;
700
+ }
700
701
}
701
702
702
703
/// Adds a key/value pair to the beginning of the node.
@@ -708,9 +709,9 @@ impl<'a, K, V> NodeRef<marker::Mut<'a>, K, V, marker::Leaf> {
708
709
unsafe {
709
710
slice_insert ( self . keys_mut ( ) , 0 , key) ;
710
711
slice_insert ( self . vals_mut ( ) , 0 , val) ;
711
- }
712
712
713
- self . as_leaf_mut ( ) . len += 1 ;
713
+ ( * self . as_leaf_mut ( ) ) . len += 1 ;
714
+ }
714
715
}
715
716
}
716
717
@@ -729,7 +730,7 @@ impl<'a, K, V> NodeRef<marker::Mut<'a>, K, V, marker::Internal> {
729
730
ptr:: write ( self . vals_mut ( ) . get_unchecked_mut ( idx) , val) ;
730
731
ptr:: write ( self . as_internal_mut ( ) . edges . get_unchecked_mut ( idx + 1 ) , edge. node ) ;
731
732
732
- self . as_leaf_mut ( ) . len += 1 ;
733
+ ( * self . as_leaf_mut ( ) ) . len += 1 ;
733
734
734
735
Handle :: new_edge ( self . reborrow_mut ( ) , idx + 1 ) . correct_parent_link ( ) ;
735
736
}
@@ -765,7 +766,7 @@ impl<'a, K, V> NodeRef<marker::Mut<'a>, K, V, marker::Internal> {
765
766
edge. node
766
767
) ;
767
768
768
- self . as_leaf_mut ( ) . len += 1 ;
769
+ ( * self . as_leaf_mut ( ) ) . len += 1 ;
769
770
770
771
self . correct_all_childrens_parent_links ( ) ;
771
772
}
@@ -789,12 +790,12 @@ impl<'a, K, V> NodeRef<marker::Mut<'a>, K, V, marker::LeafOrInternal> {
789
790
ForceResult :: Internal ( internal) => {
790
791
let edge = ptr:: read ( internal. as_internal ( ) . edges . get_unchecked ( idx + 1 ) ) ;
791
792
let mut new_root = Root { node : edge, height : internal. height - 1 } ;
792
- new_root. as_mut ( ) . as_leaf_mut ( ) . parent = ptr:: null ( ) ;
793
+ ( * new_root. as_mut ( ) . as_leaf_mut ( ) ) . parent = ptr:: null ( ) ;
793
794
Some ( new_root)
794
795
}
795
796
} ;
796
797
797
- self . as_leaf_mut ( ) . len -= 1 ;
798
+ ( * self . as_leaf_mut ( ) ) . len -= 1 ;
798
799
( key, val, edge)
799
800
}
800
801
}
@@ -822,7 +823,7 @@ impl<'a, K, V> NodeRef<marker::Mut<'a>, K, V, marker::LeafOrInternal> {
822
823
) ;
823
824
824
825
let mut new_root = Root { node : edge, height : internal. height - 1 } ;
825
- new_root. as_mut ( ) . as_leaf_mut ( ) . parent = ptr:: null ( ) ;
826
+ ( * new_root. as_mut ( ) . as_leaf_mut ( ) ) . parent = ptr:: null ( ) ;
826
827
827
828
for i in 0 ..old_len {
828
829
Handle :: new_edge ( internal. reborrow_mut ( ) , i) . correct_parent_link ( ) ;
@@ -832,7 +833,7 @@ impl<'a, K, V> NodeRef<marker::Mut<'a>, K, V, marker::LeafOrInternal> {
832
833
}
833
834
} ;
834
835
835
- self . as_leaf_mut ( ) . len -= 1 ;
836
+ ( * self . as_leaf_mut ( ) ) . len -= 1 ;
836
837
837
838
( key, val, edge)
838
839
}
@@ -1023,7 +1024,7 @@ impl<'a, K, V> Handle<NodeRef<marker::Mut<'a>, K, V, marker::Leaf>, marker::Edge
1023
1024
slice_insert ( self . node . keys_mut ( ) , self . idx , key) ;
1024
1025
slice_insert ( self . node . vals_mut ( ) , self . idx , val) ;
1025
1026
1026
- self . node . as_leaf_mut ( ) . len += 1 ;
1027
+ ( * self . node . as_leaf_mut ( ) ) . len += 1 ;
1027
1028
1028
1029
self . node . vals_mut ( ) . get_unchecked_mut ( self . idx )
1029
1030
}
@@ -1066,8 +1067,10 @@ impl<'a, K, V> Handle<NodeRef<marker::Mut<'a>, K, V, marker::Internal>, marker::
1066
1067
let idx = self . idx as u16 ;
1067
1068
let ptr = self . node . as_internal_mut ( ) as * mut _ ;
1068
1069
let mut child = self . descend ( ) ;
1069
- child. as_leaf_mut ( ) . parent = ptr;
1070
- child. as_leaf_mut ( ) . parent_idx . set ( idx) ;
1070
+ unsafe {
1071
+ ( * child. as_leaf_mut ( ) ) . parent = ptr;
1072
+ ( * child. as_leaf_mut ( ) ) . parent_idx . set ( idx) ;
1073
+ }
1071
1074
}
1072
1075
1073
1076
/// Unsafely asserts to the compiler some static information about whether the underlying
@@ -1215,7 +1218,7 @@ impl<'a, K, V> Handle<NodeRef<marker::Mut<'a>, K, V, marker::Leaf>, marker::KV>
1215
1218
new_len
1216
1219
) ;
1217
1220
1218
- self . node . as_leaf_mut ( ) . len = self . idx as u16 ;
1221
+ ( * self . node . as_leaf_mut ( ) ) . len = self . idx as u16 ;
1219
1222
new_node. len = new_len as u16 ;
1220
1223
1221
1224
(
@@ -1237,7 +1240,7 @@ impl<'a, K, V> Handle<NodeRef<marker::Mut<'a>, K, V, marker::Leaf>, marker::KV>
1237
1240
unsafe {
1238
1241
let k = slice_remove ( self . node . keys_mut ( ) , self . idx ) ;
1239
1242
let v = slice_remove ( self . node . vals_mut ( ) , self . idx ) ;
1240
- self . node . as_leaf_mut ( ) . len -= 1 ;
1243
+ ( * self . node . as_leaf_mut ( ) ) . len -= 1 ;
1241
1244
( self . left_edge ( ) , k, v)
1242
1245
}
1243
1246
}
@@ -1278,7 +1281,7 @@ impl<'a, K, V> Handle<NodeRef<marker::Mut<'a>, K, V, marker::Internal>, marker::
1278
1281
new_len + 1
1279
1282
) ;
1280
1283
1281
- self . node . as_leaf_mut ( ) . len = self . idx as u16 ;
1284
+ ( * self . node . as_leaf_mut ( ) ) . len = self . idx as u16 ;
1282
1285
new_node. data . len = new_len as u16 ;
1283
1286
1284
1287
let mut new_root = Root {
@@ -1352,9 +1355,9 @@ impl<'a, K, V> Handle<NodeRef<marker::Mut<'a>, K, V, marker::Internal>, marker::
1352
1355
for i in self . idx +1 ..self . node . len ( ) {
1353
1356
Handle :: new_edge ( self . node . reborrow_mut ( ) , i) . correct_parent_link ( ) ;
1354
1357
}
1355
- self . node . as_leaf_mut ( ) . len -= 1 ;
1358
+ ( * self . node . as_leaf_mut ( ) ) . len -= 1 ;
1356
1359
1357
- left_node. as_leaf_mut ( ) . len += right_len as u16 + 1 ;
1360
+ ( * left_node. as_leaf_mut ( ) ) . len += right_len as u16 + 1 ;
1358
1361
1359
1362
if self . node . height > 1 {
1360
1363
ptr:: copy_nonoverlapping (
@@ -1464,8 +1467,8 @@ impl<'a, K, V> Handle<NodeRef<marker::Mut<'a>, K, V, marker::Internal>, marker::
1464
1467
move_kv ( left_kv, new_left_len, parent_kv, 0 , 1 ) ;
1465
1468
}
1466
1469
1467
- left_node. reborrow_mut ( ) . as_leaf_mut ( ) . len -= count as u16 ;
1468
- right_node. reborrow_mut ( ) . as_leaf_mut ( ) . len += count as u16 ;
1470
+ ( * left_node. reborrow_mut ( ) . as_leaf_mut ( ) ) . len -= count as u16 ;
1471
+ ( * right_node. reborrow_mut ( ) . as_leaf_mut ( ) ) . len += count as u16 ;
1469
1472
1470
1473
match ( left_node. force ( ) , right_node. force ( ) ) {
1471
1474
( ForceResult :: Internal ( left) , ForceResult :: Internal ( mut right) ) => {
@@ -1525,8 +1528,8 @@ impl<'a, K, V> Handle<NodeRef<marker::Mut<'a>, K, V, marker::Internal>, marker::
1525
1528
new_right_len) ;
1526
1529
}
1527
1530
1528
- left_node. reborrow_mut ( ) . as_leaf_mut ( ) . len += count as u16 ;
1529
- right_node. reborrow_mut ( ) . as_leaf_mut ( ) . len -= count as u16 ;
1531
+ ( * left_node. reborrow_mut ( ) . as_leaf_mut ( ) ) . len += count as u16 ;
1532
+ ( * right_node. reborrow_mut ( ) . as_leaf_mut ( ) ) . len -= count as u16 ;
1530
1533
1531
1534
match ( left_node. force ( ) , right_node. force ( ) ) {
1532
1535
( ForceResult :: Internal ( left) , ForceResult :: Internal ( mut right) ) => {
@@ -1617,8 +1620,8 @@ impl<'a, K, V> Handle<NodeRef<marker::Mut<'a>, K, V, marker::LeafOrInternal>, ma
1617
1620
1618
1621
move_kv ( left_kv, left_new_len, right_kv, 0 , right_new_len) ;
1619
1622
1620
- left_node. reborrow_mut ( ) . as_leaf_mut ( ) . len = left_new_len as u16 ;
1621
- right_node. reborrow_mut ( ) . as_leaf_mut ( ) . len = right_new_len as u16 ;
1623
+ ( * left_node. reborrow_mut ( ) . as_leaf_mut ( ) ) . len = left_new_len as u16 ;
1624
+ ( * right_node. reborrow_mut ( ) . as_leaf_mut ( ) ) . len = right_new_len as u16 ;
1622
1625
1623
1626
match ( left_node. force ( ) , right_node. force ( ) ) {
1624
1627
( ForceResult :: Internal ( left) , ForceResult :: Internal ( right) ) => {
0 commit comments