perf: replace rand with fastrand

This commit is contained in:
Cheong Lau 2025-10-03 23:25:51 +10:00 committed by GitHub
parent 98d6d33c87
commit d2e080427f
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
5 changed files with 7 additions and 12 deletions

4
Cargo.lock generated
View file

@ -1133,6 +1133,7 @@ dependencies = [
"cosmic-app-list-config",
"cosmic-client-toolkit",
"cosmic-protocols",
"fastrand 2.3.0",
"futures",
"i18n-embed",
"i18n-embed-fl",
@ -1140,7 +1141,6 @@ dependencies = [
"itertools 0.14.0",
"libcosmic",
"memmap2 0.9.8",
"rand 0.9.2",
"rust-embed",
"rustix 1.1.2",
"switcheroo-control",
@ -1229,11 +1229,11 @@ dependencies = [
"anyhow",
"bluer",
"cosmic-time",
"fastrand 2.3.0",
"futures",
"i18n-embed",
"i18n-embed-fl",
"libcosmic",
"rand 0.9.2",
"rust-embed",
"tokio",
"tracing",

View file

@ -16,7 +16,7 @@ image = { version = "0.25.8", default-features = false }
itertools = "0.14.0"
libcosmic.workspace = true
memmap2 = "0.9.8"
rand = "0.9.2"
fastrand = "2.3.0"
rust-embed.workspace = true
rustix.workspace = true
switcheroo-control = { git = "https://github.com/pop-os/dbus-settings-bindings" }

View file

@ -54,7 +54,6 @@ use cosmic_protocols::toplevel_info::v1::client::zcosmic_toplevel_handle_v1::Sta
use futures::future::pending;
use iced::{Alignment, Background, Length};
use itertools::Itertools;
use rand::{Rng, rng};
use std::{borrow::Cow, collections::HashMap, path::PathBuf, rc::Rc, str::FromStr, time::Duration};
use switcheroo_control::Gpu;
use tokio::time::sleep;
@ -1084,8 +1083,7 @@ impl cosmic::Application for CosmicAppList {
}
self.active_list.clear();
let subscription_ctr = self.subscription_ctr;
let mut rng = rng();
let rand_d = rng.random_range(0..100);
let rand_d = fastrand::u64(0..100);
return iced::Task::perform(
async move {
if let Some(millis) = 2u64

View file

@ -12,7 +12,7 @@ futures.workspace = true
i18n-embed-fl.workspace = true
i18n-embed.workspace = true
libcosmic.workspace = true
rand = "0.9"
fastrand = "2.3.0"
rust-embed.workspace = true
tokio.workspace = true
tracing-log.workspace = true

View file

@ -24,7 +24,6 @@ use cosmic::{
};
use futures::{FutureExt, stream::FuturesUnordered};
use rand::Rng;
use tokio::{
spawn,
sync::{
@ -397,8 +396,7 @@ impl BluerSessionState {
),
))
.await;
let mut rng = rand::rng();
let pin_code = rng.random_range(0..999999);
let pin_code = fastrand::u32(0..999999);
Ok(format!("{:06}", pin_code))
})
})),
@ -437,8 +435,7 @@ impl BluerSessionState {
),
))
.await;
let mut rng = rand::rng();
let pin_code = rng.random_range(0..999999);
let pin_code = fastrand::u32(0..999999);
Ok(pin_code)
})
})),