Skip to content

Commit

Permalink
Apply suggestions from code review
Browse files Browse the repository at this point in the history
Co-authored-by: tpdickso <terence.dickson.prf@gmail.com>
  • Loading branch information
yotamofek and tpdickso authored Mar 20, 2024
1 parent d1b5df4 commit 095c561
Showing 1 changed file with 1 addition and 2 deletions.
3 changes: 1 addition & 2 deletions src/base/storage.rs
Original file line number Diff line number Diff line change
Expand Up @@ -213,14 +213,13 @@ pub unsafe trait RawStorageMut<T, R: Dim, C: Dim = U1>: RawStorage<T, R, C> {
/// result in stable references. If any of the data pointed to by these trait methods
/// moves as a consequence of invoking either of these methods then this default
/// trait implementation may be invalid or unsound and should be overridden.
#[inline]
unsafe fn swap_unchecked_linear(&mut self, i1: usize, i2: usize) {
// we can't just use the pointers returned from `get_address_unchecked_linear_mut` because calling a
// method taking self mutably invalidates any existing (mutable) pointers. since `get_address_unchecked_linear_mut` can
// also be overriden by a custom implementation, we can't just use `wrapping_add` assuming that's what the method does.
// instead, we use `offset_from` to compute the re-calculate the pointers from the base pointer.
// this is safe as long as this trait is implemented safely
// this is sound as long as this trait matches the Validity preconditions
// (and it's the caller's responsibility to ensure the indices are in-bounds).
let base = self.ptr_mut();
let offset1 = self.get_address_unchecked_linear_mut(i1).offset_from(base);
Expand Down

0 comments on commit 095c561

Please sign in to comment.