diff --git a/src/dimension/dynindeximpl.rs b/src/dimension/dynindeximpl.rs index 26b865a03..04dfe3aa5 100644 --- a/src/dimension/dynindeximpl.rs +++ b/src/dimension/dynindeximpl.rs @@ -49,7 +49,7 @@ impl IxDynRepr { pub fn copy_from(x: &[T]) -> Self { if x.len() <= CAP { let mut arr = [T::zero(); CAP]; - arr[..x.len()].clone_from_slice(&x[..]); + arr[..x.len()].copy_from_slice(&x[..]); IxDynRepr::Inline(x.len() as _, arr) } else { Self::from(x) diff --git a/src/lib.rs b/src/lib.rs index 53ffa3480..5b82fc644 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1557,14 +1557,11 @@ where F: FnMut(&mut A), { if let Some(slc) = self.as_slice_memory_order_mut() { - // FIXME: Use for loop when slice iterator is perf is restored - for x in slc.iter_mut() { - f(x); + slc.iter_mut().for_each(f); + } else { + for row in self.inner_rows_mut() { + row.into_iter_().fold((), |(), elt| f(elt)); } - return; - } - for row in self.inner_rows_mut() { - row.into_iter_().fold((), |(), elt| f(elt)); } } diff --git a/src/numeric_util.rs b/src/numeric_util.rs index 6ad0bb0a5..b06850fd0 100644 --- a/src/numeric_util.rs +++ b/src/numeric_util.rs @@ -6,8 +6,6 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -// https://github.com/rust-ndarray/ndarray/pull/642#discussion_r296074711 -#![allow(clippy::needless_range_loop)] use std::cmp; use crate::LinalgScalar; @@ -51,12 +49,11 @@ where // make it clear to the optimizer that this loop is short // and can not be autovectorized. - // https://github.com/rust-ndarray/ndarray/pull/642#discussion_r296337112 - for i in 0..xs.len() { + for (i, x) in xs.iter().enumerate() { if i >= 7 { break; } - acc = f(acc.clone(), xs[i].clone()) + acc = f(acc.clone(), x.clone()) } acc } @@ -103,14 +100,11 @@ where sum = sum + (p2 + p6); sum = sum + (p3 + p7); - for i in 0..xs.len() { + for (i, (&x, &y)) in xs.iter().zip(ys).enumerate() { if i >= 7 { break; } - unsafe { - // get_unchecked is needed to avoid the bounds check - sum = sum + xs[i] * *ys.get_unchecked(i); - } + sum = sum + x * y; } sum }