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

Use raw pointers for .swap(i, j) #903

Merged
merged 1 commit into from
Jan 30, 2021
Merged

Use raw pointers for .swap(i, j) #903

merged 1 commit into from
Jan 30, 2021

Conversation

bluss
Copy link
Member

@bluss bluss commented Jan 30, 2021

This fixes a minor issue where we want to avoid overlapping &mut from
the same array.

Closes #796

This fixes a minor issue where we want to avoid overlapping &mut from
the same array.
let ptr = self.as_mut_ptr();
let offset1 = index1.index_checked(&self.dim, &self.strides);
let offset2 = index2.index_checked(&self.dim, &self.strides);
if let Some(offset1) = offset1 {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fwiw, as of Rust 1.46, things like this can be written a little more nicely using Option::zip:

if let Some((offset1, offset2)) = offset1.zip(offset2) {
    unsafe { ... }
} else {
    panic!(...);
}

(or if let Some((offset1, offset2)) = Option::zip(offset1, offset2) if that looks better)

Copy link
Member Author

@bluss bluss Jan 30, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if let (Some(_), Some(_)) = (offset1, offset2) also works IMO. Now which option gives better code :) I wouldn't bother to investigate though.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Known issues and concerns w.r.t soundness and best practices
2 participants