diff options
author | Aleksey Kladov <[email protected]> | 2020-07-30 14:40:15 +0100 |
---|---|---|
committer | Aleksey Kladov <[email protected]> | 2020-07-30 14:48:35 +0100 |
commit | d061ab6c8e7d40b5b83c324282b0d8a7da6ada0a (patch) | |
tree | 97795749e06f3d8992b2a2be31761d232ea39b34 | |
parent | ee00679331b87dacc5fe608f153be160c1cb144c (diff) |
Code shuffle resiliently
-rw-r--r-- | crates/rust-analyzer/src/cli/analysis_stats.rs | 11 |
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 | ||
311 | fn shuffle<T>(rng: &mut Rand32, slice: &mut [T]) { | 311 | fn 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 | } |