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
@@ -2466,31 +2465,7 @@ where
24662465 index, axis. index( ) ) ;
24672466 let ( _, mut tail) = self . view_mut ( ) . split_at ( axis, index) ;
24682467 // 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 ( ) ) ;
24942469 // then slice the axis in place to cut out the removed final element
24952470 self . slice_axis_inplace ( axis, Slice :: new ( 0 , Some ( -1 ) , 1 ) ) ;
24962471 }
0 commit comments