-
Notifications
You must be signed in to change notification settings - Fork 13.4k
Improve ptr_rotate
performance, tests, and benches
#61937
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1130,6 +1130,44 @@ fn test_rotate_right() { | |
} | ||
} | ||
|
||
#[test] | ||
#[cfg(not(miri))] | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. These should come with a comment explaining why. I will add a |
||
fn brute_force_rotate_test_0() { | ||
// In case of edge cases involving multiple algorithms | ||
let n = 300; | ||
for len in 0..n { | ||
for s in 0..len { | ||
let mut v = Vec::with_capacity(len); | ||
for i in 0..len { | ||
v.push(i); | ||
} | ||
v[..].rotate_right(s); | ||
for i in 0..v.len() { | ||
assert_eq!(v[i], v.len().wrapping_add(i.wrapping_sub(s)) % v.len()); | ||
} | ||
} | ||
} | ||
} | ||
|
||
#[test] | ||
fn brute_force_rotate_test_1() { | ||
// `ptr_rotate` covers so many kinds of pointer usage, that this is just a good test for | ||
// pointers in general. This uses a `[usize; 4]` to hit all algorithms without overwhelming miri | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thanks you so much for keeping Miri in mind here. <3 |
||
let n = 30; | ||
for len in 0..n { | ||
for s in 0..len { | ||
let mut v: Vec<[usize; 4]> = Vec::with_capacity(len); | ||
for i in 0..len { | ||
v.push([i, 0, 0, 0]); | ||
} | ||
v[..].rotate_right(s); | ||
for i in 0..v.len() { | ||
assert_eq!(v[i][0], v.len().wrapping_add(i.wrapping_sub(s)) % v.len()); | ||
} | ||
} | ||
} | ||
} | ||
|
||
#[test] | ||
#[cfg(not(target_arch = "wasm32"))] | ||
fn sort_unstable() { | ||
|
Uh oh!
There was an error while loading. Please reload this page.