@@ -156,10 +156,10 @@ impl<K: Clone, V: Clone> Clone for BTreeMap<K, V> {
156
156
157
157
let mut in_edge = leaf. first_edge ( ) ;
158
158
while let Ok ( kv) = in_edge. right_kv ( ) {
159
- let ( k, v) = kv. into_kv ( ) ;
159
+ let ( k, v) = unsafe { kv. into_kv ( ) } ;
160
160
in_edge = kv. right_edge ( ) ;
161
161
162
- out_node. push ( k. clone ( ) , v. clone ( ) ) ;
162
+ unsafe { out_node. push ( k. clone ( ) , v. clone ( ) ) } ;
163
163
out_tree. length += 1 ;
164
164
}
165
165
}
@@ -170,10 +170,10 @@ impl<K: Clone, V: Clone> Clone for BTreeMap<K, V> {
170
170
let mut out_tree = clone_subtree ( internal. first_edge ( ) . descend ( ) ) ;
171
171
172
172
{
173
- let mut out_node = out_tree. root . push_level ( ) ;
173
+ let mut out_node = unsafe { out_tree. root . push_level ( ) } ;
174
174
let mut in_edge = internal. first_edge ( ) ;
175
175
while let Ok ( kv) = in_edge. right_kv ( ) {
176
- let ( k, v) = kv. into_kv ( ) ;
176
+ let ( k, v) = unsafe { kv. into_kv ( ) } ;
177
177
in_edge = kv. right_edge ( ) ;
178
178
179
179
let k = ( * k) . clone ( ) ;
@@ -189,7 +189,7 @@ impl<K: Clone, V: Clone> Clone for BTreeMap<K, V> {
189
189
( root, length)
190
190
} ;
191
191
192
- out_node. push ( k, v, subroot) ;
192
+ unsafe { out_node. push ( k, v, subroot) } ;
193
193
out_tree. length += 1 + sublength;
194
194
}
195
195
}
@@ -218,7 +218,7 @@ where
218
218
219
219
fn get ( & self , key : & Q ) -> Option < & K > {
220
220
match search:: search_tree ( self . root . as_ref ( ) , key) {
221
- Found ( handle) => Some ( handle. into_kv ( ) . 0 ) ,
221
+ Found ( handle) => Some ( unsafe { handle. into_kv ( ) . 0 } ) ,
222
222
GoDown ( _) => None ,
223
223
}
224
224
}
@@ -237,7 +237,7 @@ where
237
237
fn replace ( & mut self , key : K ) -> Option < K > {
238
238
self . ensure_root_is_owned ( ) ;
239
239
match search:: search_tree :: < marker:: Mut < ' _ > , K , ( ) , K > ( self . root . as_mut ( ) , & key) {
240
- Found ( handle) => Some ( mem:: replace ( handle. into_kv_mut ( ) . 0 , key) ) ,
240
+ Found ( handle) => Some ( mem:: replace ( unsafe { handle. into_kv_mut ( ) . 0 } , key) ) ,
241
241
GoDown ( handle) => {
242
242
VacantEntry { key, handle, length : & mut self . length , _marker : PhantomData }
243
243
. insert ( ( ) ) ;
@@ -536,7 +536,7 @@ impl<K: Ord, V> BTreeMap<K, V> {
536
536
Q : Ord ,
537
537
{
538
538
match search:: search_tree ( self . root . as_ref ( ) , key) {
539
- Found ( handle) => Some ( handle. into_kv ( ) . 1 ) ,
539
+ Found ( handle) => Some ( unsafe { handle. into_kv ( ) . 1 } ) ,
540
540
GoDown ( _) => None ,
541
541
}
542
542
}
@@ -563,7 +563,7 @@ impl<K: Ord, V> BTreeMap<K, V> {
563
563
Q : Ord ,
564
564
{
565
565
match search:: search_tree ( self . root . as_ref ( ) , k) {
566
- Found ( handle) => Some ( handle. into_kv ( ) ) ,
566
+ Found ( handle) => Some ( unsafe { handle. into_kv ( ) } ) ,
567
567
GoDown ( _) => None ,
568
568
}
569
569
}
@@ -592,7 +592,8 @@ impl<K: Ord, V> BTreeMap<K, V> {
592
592
K : Borrow < T > ,
593
593
{
594
594
let front = first_leaf_edge ( self . root . as_ref ( ) ) ;
595
- front. right_kv ( ) . ok ( ) . map ( Handle :: into_kv)
595
+ let handle = front. right_kv ( ) . ok ( ) ?;
596
+ Some ( unsafe { handle. into_kv ( ) } )
596
597
}
597
598
598
599
/// Returns the first entry in the map for in-place manipulation.
@@ -653,7 +654,8 @@ impl<K: Ord, V> BTreeMap<K, V> {
653
654
K : Borrow < T > ,
654
655
{
655
656
let back = last_leaf_edge ( self . root . as_ref ( ) ) ;
656
- back. left_kv ( ) . ok ( ) . map ( Handle :: into_kv)
657
+ let handle = back. left_kv ( ) . ok ( ) ?;
658
+ unsafe { Some ( handle. into_kv ( ) ) }
657
659
}
658
660
659
661
/// Returns the last entry in the map for in-place manipulation.
@@ -744,7 +746,7 @@ impl<K: Ord, V> BTreeMap<K, V> {
744
746
Q : Ord ,
745
747
{
746
748
match search:: search_tree ( self . root . as_mut ( ) , key) {
747
- Found ( handle) => Some ( handle. into_kv_mut ( ) . 1 ) ,
749
+ Found ( handle) => Some ( unsafe { handle. into_kv_mut ( ) . 1 } ) ,
748
750
GoDown ( _) => None ,
749
751
}
750
752
}
@@ -995,7 +997,7 @@ impl<K: Ord, V> BTreeMap<K, V> {
995
997
for ( key, value) in iter {
996
998
// Try to push key-value pair into the current leaf node.
997
999
if cur_node. len ( ) < node:: CAPACITY {
998
- cur_node. push ( key, value) ;
1000
+ unsafe { cur_node. push ( key, value) } ;
999
1001
} else {
1000
1002
// No space left, go up and push there.
1001
1003
let mut open_node;
@@ -1015,7 +1017,7 @@ impl<K: Ord, V> BTreeMap<K, V> {
1015
1017
}
1016
1018
Err ( node) => {
1017
1019
// We are at the top, create a new root node and push there.
1018
- open_node = node. into_root_mut ( ) . push_level ( ) ;
1020
+ open_node = unsafe { node. into_root_mut ( ) . push_level ( ) } ;
1019
1021
break ;
1020
1022
}
1021
1023
}
@@ -1025,9 +1027,9 @@ impl<K: Ord, V> BTreeMap<K, V> {
1025
1027
let tree_height = open_node. height ( ) - 1 ;
1026
1028
let mut right_tree = node:: Root :: new_leaf ( ) ;
1027
1029
for _ in 0 ..tree_height {
1028
- right_tree. push_level ( ) ;
1030
+ unsafe { right_tree. push_level ( ) } ;
1029
1031
}
1030
- open_node. push ( key, value, right_tree) ;
1032
+ unsafe { open_node. push ( key, value, right_tree) } ;
1031
1033
1032
1034
// Go down to the right-most leaf again.
1033
1035
cur_node = last_leaf_edge ( open_node. forget_type ( ) ) . into_node ( ) ;
@@ -1102,7 +1104,7 @@ impl<K: Ord, V> BTreeMap<K, V> {
1102
1104
let mut right = Self :: new ( ) ;
1103
1105
right. root = node:: Root :: new_leaf ( ) ;
1104
1106
for _ in 0 ..( self . root . as_ref ( ) . height ( ) ) {
1105
- right. root . push_level ( ) ;
1107
+ unsafe { right. root . push_level ( ) } ;
1106
1108
}
1107
1109
1108
1110
{
@@ -2387,7 +2389,7 @@ impl<'a, K: Ord, V> VacantEntry<'a, K, V> {
2387
2389
let mut ins_edge;
2388
2390
2389
2391
let mut cur_parent = match self . handle . insert ( self . key , value) {
2390
- ( Fit ( handle) , _) => return handle. into_kv_mut ( ) . 1 ,
2392
+ ( Fit ( handle) , _) => return unsafe { handle. into_kv_mut ( ) . 1 } ,
2391
2393
( Split ( left, k, v, right) , ptr) => {
2392
2394
ins_k = k;
2393
2395
ins_v = v;
@@ -2409,7 +2411,7 @@ impl<'a, K: Ord, V> VacantEntry<'a, K, V> {
2409
2411
}
2410
2412
} ,
2411
2413
Err ( root) => {
2412
- root. push_level ( ) . push ( ins_k, ins_v, ins_edge) ;
2414
+ unsafe { root. push_level ( ) . push ( ins_k, ins_v, ins_edge) } ;
2413
2415
return unsafe { & mut * out_ptr } ;
2414
2416
}
2415
2417
}
@@ -2431,7 +2433,7 @@ impl<'a, K: Ord, V> OccupiedEntry<'a, K, V> {
2431
2433
/// ```
2432
2434
#[ stable( feature = "map_entry_keys" , since = "1.10.0" ) ]
2433
2435
pub fn key ( & self ) -> & K {
2434
- self . handle . reborrow ( ) . into_kv ( ) . 0
2436
+ unsafe { self . handle . reborrow ( ) . into_kv ( ) . 0 }
2435
2437
}
2436
2438
2437
2439
/// Take ownership of the key and value from the map.
@@ -2475,7 +2477,7 @@ impl<'a, K: Ord, V> OccupiedEntry<'a, K, V> {
2475
2477
/// ```
2476
2478
#[ stable( feature = "rust1" , since = "1.0.0" ) ]
2477
2479
pub fn get ( & self ) -> & V {
2478
- self . handle . reborrow ( ) . into_kv ( ) . 1
2480
+ unsafe { self . handle . reborrow ( ) . into_kv ( ) . 1 }
2479
2481
}
2480
2482
2481
2483
/// Gets a mutable reference to the value in the entry.
@@ -2506,7 +2508,7 @@ impl<'a, K: Ord, V> OccupiedEntry<'a, K, V> {
2506
2508
/// ```
2507
2509
#[ stable( feature = "rust1" , since = "1.0.0" ) ]
2508
2510
pub fn get_mut ( & mut self ) -> & mut V {
2509
- self . handle . kv_mut ( ) . 1
2511
+ unsafe { self . handle . kv_mut ( ) . 1 }
2510
2512
}
2511
2513
2512
2514
/// Converts the entry into a mutable reference to its value.
@@ -2532,7 +2534,7 @@ impl<'a, K: Ord, V> OccupiedEntry<'a, K, V> {
2532
2534
/// ```
2533
2535
#[ stable( feature = "rust1" , since = "1.0.0" ) ]
2534
2536
pub fn into_mut ( self ) -> & ' a mut V {
2535
- self . handle . into_kv_mut ( ) . 1
2537
+ unsafe { self . handle . into_kv_mut ( ) . 1 }
2536
2538
}
2537
2539
2538
2540
/// Sets the value of the entry with the `OccupiedEntry`'s key,
@@ -2584,17 +2586,17 @@ impl<'a, K: Ord, V> OccupiedEntry<'a, K, V> {
2584
2586
2585
2587
let ( small_leaf, old_key, old_val) = match self . handle . force ( ) {
2586
2588
Leaf ( leaf) => {
2587
- let ( hole, old_key, old_val) = leaf. remove ( ) ;
2589
+ let ( hole, old_key, old_val) = unsafe { leaf. remove ( ) } ;
2588
2590
( hole. into_node ( ) , old_key, old_val)
2589
2591
}
2590
2592
Internal ( mut internal) => {
2591
- let key_loc = internal. kv_mut ( ) . 0 as * mut K ;
2592
- let val_loc = internal. kv_mut ( ) . 1 as * mut V ;
2593
+ let key_loc = unsafe { internal. kv_mut ( ) . 0 as * mut K } ;
2594
+ let val_loc = unsafe { internal. kv_mut ( ) . 1 as * mut V } ;
2593
2595
2594
2596
let to_remove = first_leaf_edge ( internal. right_edge ( ) . descend ( ) ) . right_kv ( ) . ok ( ) ;
2595
2597
let to_remove = unsafe { unwrap_unchecked ( to_remove) } ;
2596
2598
2597
- let ( hole, key, val) = to_remove. remove ( ) ;
2599
+ let ( hole, key, val) = unsafe { to_remove. remove ( ) } ;
2598
2600
2599
2601
let old_key = unsafe { mem:: replace ( & mut * key_loc, key) } ;
2600
2602
let old_val = unsafe { mem:: replace ( & mut * val_loc, val) } ;
0 commit comments