Skip to content

Commit d061ab6

Browse files
committed
Code shuffle resiliently
1 parent ee00679 commit d061ab6

File tree

1 file changed

+8
-3
lines changed

1 file changed

+8
-3
lines changed

crates/rust-analyzer/src/cli/analysis_stats.rs

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -309,8 +309,13 @@ pub fn analysis_stats(
309309
}
310310

311311
fn shuffle<T>(rng: &mut Rand32, slice: &mut [T]) {
312-
for i in (1..slice.len()).rev() {
313-
let idx = rng.rand_range(0..i as u32) as usize;
314-
slice.swap(idx, i)
312+
for i in 0..slice.len() {
313+
randomize_first(rng, &mut slice[i..]);
314+
}
315+
316+
fn randomize_first<T>(rng: &mut Rand32, slice: &mut [T]) {
317+
assert!(!slice.is_empty());
318+
let idx = rng.rand_range(0..slice.len() as u32) as usize;
319+
slice.swap(0, idx);
315320
}
316321
}

0 commit comments

Comments
 (0)