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
@@ -2466,31 +2465,7 @@ where
2466
2465
index, axis. index( ) ) ;
2467
2466
let ( _, mut tail) = self . view_mut ( ) . split_at ( axis, index) ;
2468
2467
// shift elements to the front
2469
- // use swapping to keep all elements initialized (as required by owned storage)
2470
- Zip :: from ( tail. lanes_mut ( axis) ) . for_each ( |mut lane| {
2471
- let mut lane_iter = lane. iter_mut ( ) ;
2472
- let mut dst = if let Some ( dst) = lane_iter. next ( ) { dst } else { return } ;
2473
-
2474
- // Logically we do a circular swap here, all elements in a chain
2475
- // Using MaybeUninit to avoid unecessary writes in the safe swap solution
2476
- //
2477
- // for elt in lane_iter {
2478
- // std::mem::swap(dst, elt);
2479
- // dst = elt;
2480
- // }
2481
- //
2482
- let guard = AbortIfPanic ( & "remove_index: temporarily moving out of owned value" ) ;
2483
- let mut slot = MaybeUninit :: < A > :: uninit ( ) ;
2484
- unsafe {
2485
- slot. as_mut_ptr ( ) . copy_from_nonoverlapping ( dst, 1 ) ;
2486
- for elt in lane_iter {
2487
- ( dst as * mut A ) . copy_from_nonoverlapping ( elt, 1 ) ;
2488
- dst = elt;
2489
- }
2490
- ( dst as * mut A ) . copy_from_nonoverlapping ( slot. as_ptr ( ) , 1 ) ;
2491
- }
2492
- guard. defuse ( ) ;
2493
- } ) ;
2468
+ Zip :: from ( tail. lanes_mut ( axis) ) . for_each ( |mut lane| lane. rotate1_front ( ) ) ;
2494
2469
// then slice the axis in place to cut out the removed final element
2495
2470
self . slice_axis_inplace ( axis, Slice :: new ( 0 , Some ( -1 ) , 1 ) ) ;
2496
2471
}
0 commit comments