File tree 3 files changed +9
-18
lines changed
3 files changed +9
-18
lines changed Original file line number Diff line number Diff line change @@ -49,7 +49,7 @@ impl<T: Copy + Zero> IxDynRepr<T> {
49
49
pub fn copy_from ( x : & [ T ] ) -> Self {
50
50
if x. len ( ) <= CAP {
51
51
let mut arr = [ T :: zero ( ) ; CAP ] ;
52
- arr[ ..x. len ( ) ] . clone_from_slice ( & x[ ..] ) ;
52
+ arr[ ..x. len ( ) ] . copy_from_slice ( & x[ ..] ) ;
53
53
IxDynRepr :: Inline ( x. len ( ) as _ , arr)
54
54
} else {
55
55
Self :: from ( x)
Original file line number Diff line number Diff line change @@ -1538,14 +1538,11 @@ where
1538
1538
F : FnMut ( & mut A ) ,
1539
1539
{
1540
1540
if let Some ( slc) = self . as_slice_memory_order_mut ( ) {
1541
- // FIXME: Use for loop when slice iterator is perf is restored
1542
- for x in slc. iter_mut ( ) {
1543
- f ( x) ;
1541
+ slc. iter_mut ( ) . for_each ( f) ;
1542
+ } else {
1543
+ for row in self . inner_rows_mut ( ) {
1544
+ row. into_iter_ ( ) . fold ( ( ) , |( ) , elt| f ( elt) ) ;
1544
1545
}
1545
- return ;
1546
- }
1547
- for row in self . inner_rows_mut ( ) {
1548
- row. into_iter_ ( ) . fold ( ( ) , |( ) , elt| f ( elt) ) ;
1549
1546
}
1550
1547
}
1551
1548
Original file line number Diff line number Diff line change 6
6
// option. This file may not be copied, modified, or distributed
7
7
// except according to those terms.
8
8
9
- // https://github.com/rust-ndarray/ndarray/pull/642#discussion_r296074711
10
- #![ allow( clippy:: needless_range_loop) ]
11
9
use std:: cmp;
12
10
13
11
use crate :: LinalgScalar ;
@@ -51,12 +49,11 @@ where
51
49
52
50
// make it clear to the optimizer that this loop is short
53
51
// and can not be autovectorized.
54
- // https://github.com/rust-ndarray/ndarray/pull/642#discussion_r296337112
55
- for i in 0 ..xs. len ( ) {
52
+ for ( i, x) in xs. iter ( ) . enumerate ( ) {
56
53
if i >= 7 {
57
54
break ;
58
55
}
59
- acc = f ( acc. clone ( ) , xs [ i ] . clone ( ) )
56
+ acc = f ( acc. clone ( ) , x . clone ( ) )
60
57
}
61
58
acc
62
59
}
@@ -103,14 +100,11 @@ where
103
100
sum = sum + ( p2 + p6) ;
104
101
sum = sum + ( p3 + p7) ;
105
102
106
- for i in 0 ..xs . len ( ) {
103
+ for ( i , ( & x , & y ) ) in xs . iter ( ) . zip ( ys ) . enumerate ( ) {
107
104
if i >= 7 {
108
105
break ;
109
106
}
110
- unsafe {
111
- // get_unchecked is needed to avoid the bounds check
112
- sum = sum + xs[ i] * * ys. get_unchecked ( i) ;
113
- }
107
+ sum = sum + x * y;
114
108
}
115
109
sum
116
110
}
You can’t perform that action at this time.
0 commit comments