mirror of
https://github.com/matrix-org/matrix-hookshot.git
synced 2025-03-10 13:17:08 +00:00
Make shuffle function much cheaper
This commit is contained in:
parent
3d502c5dba
commit
ade6f0b57c
@ -97,14 +97,10 @@ impl QueueWithBackoff {
|
|||||||
#[napi]
|
#[napi]
|
||||||
pub fn shuffle(&mut self) {
|
pub fn shuffle(&mut self) {
|
||||||
let mut rng = rand::thread_rng();
|
let mut rng = rand::thread_rng();
|
||||||
let old_queue = self.queue.clone();
|
let items = self.queue.drain(..);
|
||||||
self.queue.clear();
|
let len = items.len();
|
||||||
for item in old_queue {
|
for item in items.choose_multiple(&mut rng, len) {
|
||||||
if rng.gen_bool(0.5) {
|
self.queue.push_front(item);
|
||||||
self.queue.push_front(item);
|
|
||||||
} else {
|
|
||||||
self.queue.push_back(item);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user