aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorbors[bot] <26634292+bors[bot]@users.noreply.github.com>2020-07-30 14:49:02 +0100
committerGitHub <[email protected]>2020-07-30 14:49:02 +0100
commit323fd64abde2aced9427e4470b626a898b80a783 (patch)
treead4d7aff56fa0e491d5b686e71ab817a13c59334
parent97fb5daf723c520b0361ade3e44f130257b1fe96 (diff)
parentd061ab6c8e7d40b5b83c324282b0d8a7da6ada0a (diff)
Merge #5593
5593: Code shuffle resiliently r=matklad a=matklad Co-authored-by: Aleksey Kladov <[email protected]>
-rw-r--r--crates/rust-analyzer/src/cli/analysis_stats.rs11
1 files changed, 8 insertions, 3 deletions
diff --git a/crates/rust-analyzer/src/cli/analysis_stats.rs b/crates/rust-analyzer/src/cli/analysis_stats.rs
index 187a0ebe6..a270eb481 100644
--- a/crates/rust-analyzer/src/cli/analysis_stats.rs
+++ b/crates/rust-analyzer/src/cli/analysis_stats.rs
@@ -309,8 +309,13 @@ pub fn analysis_stats(
309} 309}
310 310
311fn shuffle<T>(rng: &mut Rand32, slice: &mut [T]) { 311fn shuffle<T>(rng: &mut Rand32, slice: &mut [T]) {
312 for i in (1..slice.len()).rev() { 312 for i in 0..slice.len() {
313 let idx = rng.rand_range(0..i as u32) as usize; 313 randomize_first(rng, &mut slice[i..]);
314 slice.swap(idx, 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);
315 } 320 }
316} 321}