File tree 1 file changed +8
-4
lines changed
library/alloc/src/collections/btree
1 file changed +8
-4
lines changed Original file line number Diff line number Diff line change @@ -1608,15 +1608,19 @@ pub mod marker {
1608
1608
1609
1609
unsafe fn slice_insert < T > ( slice : & mut [ T ] , idx : usize , val : T ) {
1610
1610
unsafe {
1611
- ptr:: copy ( slice. as_ptr ( ) . add ( idx) , slice. as_mut_ptr ( ) . add ( idx + 1 ) , slice. len ( ) - idx) ;
1612
- ptr:: write ( slice. get_unchecked_mut ( idx) , val) ;
1611
+ let len = slice. len ( ) ;
1612
+ let slice_ptr = slice. as_mut_ptr ( ) ;
1613
+ ptr:: copy ( slice_ptr. add ( idx) , slice_ptr. add ( idx + 1 ) , len - idx) ;
1614
+ ptr:: write ( slice_ptr. add ( idx) , val) ;
1613
1615
}
1614
1616
}
1615
1617
1616
1618
unsafe fn slice_remove < T > ( slice : & mut [ T ] , idx : usize ) -> T {
1617
1619
unsafe {
1618
- let ret = ptr:: read ( slice. get_unchecked ( idx) ) ;
1619
- ptr:: copy ( slice. as_ptr ( ) . add ( idx + 1 ) , slice. as_mut_ptr ( ) . add ( idx) , slice. len ( ) - idx - 1 ) ;
1620
+ let len = slice. len ( ) ;
1621
+ let slice_ptr = slice. as_mut_ptr ( ) ;
1622
+ let ret = ptr:: read ( slice_ptr. add ( idx) ) ;
1623
+ ptr:: copy ( slice_ptr. add ( idx + 1 ) , slice_ptr. add ( idx) , len - idx - 1 ) ;
1620
1624
ret
1621
1625
}
1622
1626
}
You can’t perform that action at this time.
0 commit comments