mirror of
https://github.com/rust-lang/rust-analyzer
synced 2024-11-15 01:17:27 +00:00
Merge #5593
5593: Code shuffle resiliently r=matklad a=matklad Co-authored-by: Aleksey Kladov <aleksey.kladov@gmail.com>
This commit is contained in:
commit
323fd64abd
1 changed files with 8 additions and 3 deletions
|
@ -309,8 +309,13 @@ pub fn analysis_stats(
|
|||
}
|
||||
|
||||
fn shuffle<T>(rng: &mut Rand32, slice: &mut [T]) {
|
||||
for i in (1..slice.len()).rev() {
|
||||
let idx = rng.rand_range(0..i as u32) as usize;
|
||||
slice.swap(idx, i)
|
||||
for i in 0..slice.len() {
|
||||
randomize_first(rng, &mut slice[i..]);
|
||||
}
|
||||
|
||||
fn randomize_first<T>(rng: &mut Rand32, slice: &mut [T]) {
|
||||
assert!(!slice.is_empty());
|
||||
let idx = rng.rand_range(0..slice.len() as u32) as usize;
|
||||
slice.swap(0, idx);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue