66// option. This file may not be copied, modified, or distributed
77// except according to those terms.
88
9- use std:: mem:: { size_of, ManuallyDrop , MaybeUninit } ;
9+ use std:: mem:: { size_of, ManuallyDrop } ;
1010use alloc:: slice;
1111use alloc:: vec;
1212use alloc:: vec:: Vec ;
@@ -26,7 +26,6 @@ use crate::dimension::broadcast::co_broadcast;
2626use crate :: error:: { self , ErrorKind , ShapeError , from_kind} ;
2727use crate :: math_cell:: MathCell ;
2828use crate :: itertools:: zip;
29- use crate :: low_level_util:: AbortIfPanic ;
3029use crate :: zip:: { IntoNdProducer , Zip } ;
3130use crate :: AxisDescription ;
3231
@@ -2464,31 +2463,7 @@ where
24642463 index, axis. index( ) ) ;
24652464 let ( _, mut tail) = self . view_mut ( ) . split_at ( axis, index) ;
24662465 // 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 ( ) ) ;
24922467 // then slice the axis in place to cut out the removed final element
24932468 self . slice_axis_inplace ( axis, Slice :: new ( 0 , Some ( -1 ) , 1 ) ) ;
24942469 }
0 commit comments