Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adjust unsafe blocks for the BaseMatrixMut trait #202

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 9 additions & 9 deletions src/matrix/base/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -616,10 +616,10 @@ pub trait BaseMatrix<T>: Sized {
}

for row_idx in row_iter.clone() {
unsafe {
let row = self.row_unchecked(*row_idx);

let row = unsafe { self.row_unchecked(*row_idx) };
mat_vec.extend_from_slice(row.raw_slice());
}

}

Matrix {
Expand Down Expand Up @@ -1398,20 +1398,20 @@ pub trait BaseMatrixMut<T>: BaseMatrix<T> {
format!("Row index {0} larger than row count {1}", b, self.rows()));

if a != b {
unsafe {
let row_a = slice::from_raw_parts_mut(self.as_mut_ptr()

let row_a = unsafe { slice::from_raw_parts_mut(self.as_mut_ptr()
.offset((self.row_stride() * a) as
isize),
self.cols());
let row_b = slice::from_raw_parts_mut(self.as_mut_ptr()
self.cols()) };
let row_b = unsafe { slice::from_raw_parts_mut(self.as_mut_ptr()
.offset((self.row_stride() * b) as
isize),
self.cols());
self.cols()) };

for (x, y) in row_a.into_iter().zip(row_b.into_iter()) {
mem::swap(x, y);
}
}

}

}
Expand Down
16 changes: 8 additions & 8 deletions src/matrix/iter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ impl<'a, T> Iterator for $slice_iter<'a, T> {
let end = self.slice_rows * self.row_stride;
// Set the position of the next element
if offset < end {
unsafe {
let iter_ptr = self.slice_start.offset(offset as isize);

let iter_ptr = unsafe { self.slice_start.offset(offset as isize) };

// If end of row, set to start of next row
if self.col_pos + 1 == self.slice_cols {
Expand All @@ -27,8 +27,8 @@ impl<'a, T> Iterator for $slice_iter<'a, T> {
self.col_pos += 1usize;
}

Some(mem::transmute(iter_ptr))
}
Some(unsafe { mem::transmute(iter_ptr) })

} else {
None
}
Expand Down Expand Up @@ -119,12 +119,12 @@ impl<'a, T> Iterator for $cols<'a, T> {
}

let column: $col_type;
unsafe {
let ptr = self.slice_start.offset(self.col_pos as isize);

let ptr = unsafe { self.slice_start.offset(self.col_pos as isize) };
column = $col_base {
col: $slice_base::from_raw_parts(ptr, self.slice_rows, 1, self.row_stride as usize)
col: unsafe { $slice_base::from_raw_parts(ptr, self.slice_rows, 1, self.row_stride as usize) }
};
}

self.col_pos += 1;
Some(column)
}
Expand Down