Improve performance of map_row()
Before: test bench_solve100 ... bench: 64,727 ns/iter (+/- 691) test bench_solve1000 ... bench: 7,160,735 ns/iter (+/- 315,280) After: test bench_solve100 ... bench: 59,998 ns/iter (+/- 4,502) test bench_solve1000 ... bench: 6,761,411 ns/iter (+/- 379,337)
This commit is contained in:
parent
f8329d5994
commit
d33071e044
@ -51,9 +51,13 @@ impl<T: Copy> SquareMatrix<T> {
|
||||
|
||||
#[inline(always)]
|
||||
pub fn map_row<F: Fn(T) -> T>(&mut self, row: usize, f: F) {
|
||||
for col in 0..self.n {
|
||||
let n = f(self[(row, col)]);
|
||||
self[(row, col)] = n;
|
||||
assert!(row < self.n);
|
||||
|
||||
let mut row_slice = &mut self.data[row*self.n .. (row+1)*self.n];
|
||||
debug_assert!(row_slice.len() == self.n);
|
||||
|
||||
for elm in row_slice.iter_mut() {
|
||||
*elm = f(*elm);
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user