6
6
// option. This file may not be copied, modified, or distributed
7
7
// except according to those terms.
8
8
9
- use std:: mem:: { size_of, ManuallyDrop , MaybeUninit } ;
9
+ use std:: mem:: { size_of, ManuallyDrop } ;
10
10
use alloc:: slice;
11
11
use alloc:: vec;
12
12
use alloc:: vec:: Vec ;
@@ -26,7 +26,6 @@ use crate::dimension::broadcast::co_broadcast;
26
26
use crate :: error:: { self , ErrorKind , ShapeError , from_kind} ;
27
27
use crate :: math_cell:: MathCell ;
28
28
use crate :: itertools:: zip;
29
- use crate :: low_level_util:: AbortIfPanic ;
30
29
use crate :: zip:: { IntoNdProducer , Zip } ;
31
30
use crate :: AxisDescription ;
32
31
@@ -2464,31 +2463,7 @@ where
2464
2463
index, axis. index( ) ) ;
2465
2464
let ( _, mut tail) = self . view_mut ( ) . split_at ( axis, index) ;
2466
2465
// shift elements to the front
2467
- // use swapping to keep all elements initialized (as required by owned storage)
2468
- Zip :: from ( tail. lanes_mut ( axis) ) . for_each ( |mut lane| {
2469
- let mut lane_iter = lane. iter_mut ( ) ;
2470
- let mut dst = if let Some ( dst) = lane_iter. next ( ) { dst } else { return } ;
2471
-
2472
- // Logically we do a circular swap here, all elements in a chain
2473
- // Using MaybeUninit to avoid unecessary writes in the safe swap solution
2474
- //
2475
- // for elt in lane_iter {
2476
- // std::mem::swap(dst, elt);
2477
- // dst = elt;
2478
- // }
2479
- //
2480
- let guard = AbortIfPanic ( & "remove_index: temporarily moving out of owned value" ) ;
2481
- let mut slot = MaybeUninit :: < A > :: uninit ( ) ;
2482
- unsafe {
2483
- slot. as_mut_ptr ( ) . copy_from_nonoverlapping ( dst, 1 ) ;
2484
- for elt in lane_iter {
2485
- ( dst as * mut A ) . copy_from_nonoverlapping ( elt, 1 ) ;
2486
- dst = elt;
2487
- }
2488
- ( dst as * mut A ) . copy_from_nonoverlapping ( slot. as_ptr ( ) , 1 ) ;
2489
- }
2490
- guard. defuse ( ) ;
2491
- } ) ;
2466
+ Zip :: from ( tail. lanes_mut ( axis) ) . for_each ( |mut lane| lane. rotate1_front ( ) ) ;
2492
2467
// then slice the axis in place to cut out the removed final element
2493
2468
self . slice_axis_inplace ( axis, Slice :: new ( 0 , Some ( -1 ) , 1 ) ) ;
2494
2469
}
0 commit comments