From abb7a4e9acd7fd4b32dfe31ef69972d3bd0a5631 Mon Sep 17 00:00:00 2001 From: John Nunley Date: Mon, 3 Jul 2023 07:59:34 -0700 Subject: [PATCH] version: Use fastrand v2.0.0 --- Cargo.toml | 2 +- src/wayland/buffer.rs | 5 ++++- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 4f41b35..cf9d809 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -39,7 +39,7 @@ wayland-sys = "0.30.0" x11rb = { version = "0.12.0", features = ["allow-unsafe-code", "shm"], optional = true } [target.'cfg(all(unix, not(any(target_vendor = "apple", target_os = "android", target_os = "redox", target_os = "linux", target_os = "freebsd"))))'.dependencies] -fastrand = { version = "1.8.0", optional = true } +fastrand = { version = "2.0.0", optional = true } [target.'cfg(target_os = "windows")'.dependencies.windows-sys] version = "0.48.0" diff --git a/src/wayland/buffer.rs b/src/wayland/buffer.rs index ed8855f..51a9466 100644 --- a/src/wayland/buffer.rs +++ b/src/wayland/buffer.rs @@ -49,9 +49,12 @@ fn create_memfile() -> File { }; use std::iter; + // Use a cached RNG to avoid hammering the thread local. + let mut rng = fastrand::Rng::new(); + for _ in 0..=4 { let mut name = String::from("softbuffer-"); - name.extend(iter::repeat_with(fastrand::alphanumeric).take(7)); + name.extend(iter::repeat_with(|| rng.alphanumeric()).take(7)); name.push('\0'); let name = unsafe { CStr::from_bytes_with_nul_unchecked(name.as_bytes()) };