diff --git a/src/square_matrix.rs b/src/square_matrix.rs index ec2f185..329d2b4 100644 --- a/src/square_matrix.rs +++ b/src/square_matrix.rs @@ -51,9 +51,13 @@ impl SquareMatrix { #[inline(always)] pub fn map_row 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); } }