1
Fork 0
mirror of https://github.com/RGBCube/uutils-coreutils synced 2025-07-28 11:37:44 +00:00

Remove once_cell dependency & use LazyLock

This commit is contained in:
Daniel Hofstetter 2025-03-05 11:02:56 +01:00
parent 0f9b36b0d4
commit e177f7a6b0
9 changed files with 15 additions and 27 deletions

3
Cargo.lock generated
View file

@ -474,7 +474,6 @@ dependencies = [
"libc", "libc",
"nix", "nix",
"num-prime", "num-prime",
"once_cell",
"phf", "phf",
"phf_codegen", "phf_codegen",
"pretty_assertions", "pretty_assertions",
@ -2899,7 +2898,6 @@ dependencies = [
"hostname", "hostname",
"lscolors", "lscolors",
"number_prefix", "number_prefix",
"once_cell",
"selinux", "selinux",
"terminal_size", "terminal_size",
"uucore", "uucore",
@ -3509,7 +3507,6 @@ dependencies = [
"memchr", "memchr",
"nix", "nix",
"number_prefix", "number_prefix",
"once_cell",
"os_display", "os_display",
"regex", "regex",
"sha1", "sha1",

View file

@ -314,7 +314,6 @@ num-bigint = "0.4.4"
num-prime = "0.4.4" num-prime = "0.4.4"
num-traits = "0.2.19" num-traits = "0.2.19"
number_prefix = "0.4" number_prefix = "0.4"
once_cell = "1.19.0"
onig = { version = "~6.4", default-features = false } onig = { version = "~6.4", default-features = false }
parse_datetime = "0.8.0" parse_datetime = "0.8.0"
phf = "0.11.2" phf = "0.11.2"
@ -366,7 +365,6 @@ uu_base32 = { version = "0.0.29", path = "src/uu/base32" }
[dependencies] [dependencies]
clap = { workspace = true } clap = { workspace = true }
once_cell = { workspace = true }
uucore = { workspace = true } uucore = { workspace = true }
clap_complete = { workspace = true } clap_complete = { workspace = true }
clap_mangen = { workspace = true } clap_mangen = { workspace = true }

View file

@ -24,7 +24,6 @@ glob = { workspace = true }
hostname = { workspace = true } hostname = { workspace = true }
lscolors = { workspace = true } lscolors = { workspace = true }
number_prefix = { workspace = true } number_prefix = { workspace = true }
once_cell = { workspace = true }
selinux = { workspace = true, optional = true } selinux = { workspace = true, optional = true }
terminal_size = { workspace = true } terminal_size = { workspace = true }
uucore = { workspace = true, features = [ uucore = { workspace = true, features = [

View file

@ -3057,7 +3057,7 @@ fn get_inode(metadata: &Metadata) -> String {
// Currently getpwuid is `linux` target only. If it's broken out into // Currently getpwuid is `linux` target only. If it's broken out into
// a posix-compliant attribute this can be updated... // a posix-compliant attribute this can be updated...
#[cfg(unix)] #[cfg(unix)]
use once_cell::sync::Lazy; use std::sync::LazyLock;
#[cfg(unix)] #[cfg(unix)]
use std::sync::Mutex; use std::sync::Mutex;
#[cfg(unix)] #[cfg(unix)]
@ -3066,7 +3066,8 @@ use uucore::fs::FileInformation;
#[cfg(unix)] #[cfg(unix)]
fn cached_uid2usr(uid: u32) -> String { fn cached_uid2usr(uid: u32) -> String {
static UID_CACHE: Lazy<Mutex<HashMap<u32, String>>> = Lazy::new(|| Mutex::new(HashMap::new())); static UID_CACHE: LazyLock<Mutex<HashMap<u32, String>>> =
LazyLock::new(|| Mutex::new(HashMap::new()));
let mut uid_cache = UID_CACHE.lock().unwrap(); let mut uid_cache = UID_CACHE.lock().unwrap();
uid_cache uid_cache
@ -3086,7 +3087,8 @@ fn display_uname(metadata: &Metadata, config: &Config) -> String {
#[cfg(all(unix, not(target_os = "redox")))] #[cfg(all(unix, not(target_os = "redox")))]
fn cached_gid2grp(gid: u32) -> String { fn cached_gid2grp(gid: u32) -> String {
static GID_CACHE: Lazy<Mutex<HashMap<u32, String>>> = Lazy::new(|| Mutex::new(HashMap::new())); static GID_CACHE: LazyLock<Mutex<HashMap<u32, String>>> =
LazyLock::new(|| Mutex::new(HashMap::new()));
let mut gid_cache = GID_CACHE.lock().unwrap(); let mut gid_cache = GID_CACHE.lock().unwrap();
gid_cache gid_cache

View file

@ -45,7 +45,6 @@ data-encoding = { version = "2.6", optional = true }
data-encoding-macro = { version = "0.1.15", optional = true } data-encoding-macro = { version = "0.1.15", optional = true }
z85 = { version = "3.0.5", optional = true } z85 = { version = "3.0.5", optional = true }
libc = { workspace = true, optional = true } libc = { workspace = true, optional = true }
once_cell = { workspace = true }
os_display = "0.1.3" os_display = "0.1.3"
digest = { workspace = true, optional = true } digest = { workspace = true, optional = true }
@ -68,7 +67,6 @@ xattr = { workspace = true, optional = true }
[dev-dependencies] [dev-dependencies]
clap = { workspace = true } clap = { workspace = true }
once_cell = { workspace = true }
tempfile = { workspace = true } tempfile = { workspace = true }
[target.'cfg(target_os = "windows")'.dependencies] [target.'cfg(target_os = "windows")'.dependencies]

View file

@ -485,8 +485,7 @@ mod tests {
use super::*; use super::*;
// Required to instantiate mutex in shared context // Required to instantiate mutex in shared context
use clap::Command; use clap::Command;
use once_cell::sync::Lazy; use std::sync::{LazyLock, Mutex};
use std::sync::Mutex;
// The mutex is required here as by default all tests are run as separate // The mutex is required here as by default all tests are run as separate
// threads under the same parent process. As environment variables are // threads under the same parent process. As environment variables are
@ -494,7 +493,7 @@ mod tests {
// occur if no precautions are taken. Thus we have all tests that rely on // occur if no precautions are taken. Thus we have all tests that rely on
// environment variables lock this empty mutex to ensure they don't access // environment variables lock this empty mutex to ensure they don't access
// it concurrently. // it concurrently.
static TEST_MUTEX: Lazy<Mutex<()>> = Lazy::new(|| Mutex::new(())); static TEST_MUTEX: LazyLock<Mutex<()>> = LazyLock::new(|| Mutex::new(()));
// Environment variable for "VERSION_CONTROL" // Environment variable for "VERSION_CONTROL"
static ENV_VERSION_CONTROL: &str = "VERSION_CONTROL"; static ENV_VERSION_CONTROL: &str = "VERSION_CONTROL";

View file

@ -43,9 +43,7 @@ use std::io::Error as IOError;
use std::io::ErrorKind; use std::io::ErrorKind;
use std::io::Result as IOResult; use std::io::Result as IOResult;
use std::ptr; use std::ptr;
use std::sync::Mutex; use std::sync::{LazyLock, Mutex};
use once_cell::sync::Lazy;
extern "C" { extern "C" {
/// From: `<https://man7.org/linux/man-pages/man3/getgrouplist.3.html>` /// From: `<https://man7.org/linux/man-pages/man3/getgrouplist.3.html>`
@ -276,7 +274,7 @@ pub trait Locate<K> {
// to, so we must copy all the data we want before releasing the lock. // to, so we must copy all the data we want before releasing the lock.
// (Technically we must also ensure that the raw functions aren't being called // (Technically we must also ensure that the raw functions aren't being called
// anywhere else in the program.) // anywhere else in the program.)
static PW_LOCK: Lazy<Mutex<()>> = Lazy::new(|| Mutex::new(())); static PW_LOCK: LazyLock<Mutex<()>> = LazyLock::new(|| Mutex::new(()));
macro_rules! f { macro_rules! f {
($fnam:ident, $fid:ident, $t:ident, $st:ident) => { ($fnam:ident, $fid:ident, $t:ident, $st:ident) => {

View file

@ -304,7 +304,7 @@ impl Utmpx {
// I believe the only technical memory unsafety that could happen is a data // I believe the only technical memory unsafety that could happen is a data
// race while copying the data out of the pointer returned by getutxent(), but // race while copying the data out of the pointer returned by getutxent(), but
// ordinary race conditions are also very much possible. // ordinary race conditions are also very much possible.
static LOCK: Lazy<Mutex<()>> = Lazy::new(|| Mutex::new(())); static LOCK: LazyLock<Mutex<()>> = LazyLock::new(|| Mutex::new(()));
/// Iterator of login records /// Iterator of login records
pub struct UtmpxIter { pub struct UtmpxIter {

View file

@ -115,16 +115,13 @@ use nix::sys::signal::{
sigaction, SaFlags, SigAction, SigHandler::SigDfl, SigSet, Signal::SIGBUS, Signal::SIGSEGV, sigaction, SaFlags, SigAction, SigHandler::SigDfl, SigSet, Signal::SIGBUS, Signal::SIGSEGV,
}; };
use std::borrow::Cow; use std::borrow::Cow;
use std::ffi::OsStr; use std::ffi::{OsStr, OsString};
use std::ffi::OsString;
use std::io::{BufRead, BufReader}; use std::io::{BufRead, BufReader};
use std::iter; use std::iter;
#[cfg(unix)] #[cfg(unix)]
use std::os::unix::ffi::{OsStrExt, OsStringExt}; use std::os::unix::ffi::{OsStrExt, OsStringExt};
use std::str; use std::str;
use std::sync::atomic::Ordering; use std::sync::{atomic::Ordering, LazyLock};
use once_cell::sync::Lazy;
/// Disables the custom signal handlers installed by Rust for stack-overflow handling. With those custom signal handlers processes ignore the first SIGBUS and SIGSEGV signal they receive. /// Disables the custom signal handlers installed by Rust for stack-overflow handling. With those custom signal handlers processes ignore the first SIGBUS and SIGSEGV signal they receive.
/// See <https://github.com/rust-lang/rust/blob/8ac1525e091d3db28e67adcbbd6db1e1deaa37fb/src/libstd/sys/unix/stack_overflow.rs#L71-L92> for details. /// See <https://github.com/rust-lang/rust/blob/8ac1525e091d3db28e67adcbbd6db1e1deaa37fb/src/libstd/sys/unix/stack_overflow.rs#L71-L92> for details.
@ -194,9 +191,9 @@ pub fn set_utility_is_second_arg() {
// args_os() can be expensive to call, it copies all of argv before iterating. // args_os() can be expensive to call, it copies all of argv before iterating.
// So if we want only the first arg or so it's overkill. We cache it. // So if we want only the first arg or so it's overkill. We cache it.
static ARGV: Lazy<Vec<OsString>> = Lazy::new(|| wild::args_os().collect()); static ARGV: LazyLock<Vec<OsString>> = LazyLock::new(|| wild::args_os().collect());
static UTIL_NAME: Lazy<String> = Lazy::new(|| { static UTIL_NAME: LazyLock<String> = LazyLock::new(|| {
let base_index = usize::from(get_utility_is_second_arg()); let base_index = usize::from(get_utility_is_second_arg());
let is_man = usize::from(ARGV[base_index].eq("manpage")); let is_man = usize::from(ARGV[base_index].eq("manpage"));
let argv_index = base_index + is_man; let argv_index = base_index + is_man;
@ -209,7 +206,7 @@ pub fn util_name() -> &'static str {
&UTIL_NAME &UTIL_NAME
} }
static EXECUTION_PHRASE: Lazy<String> = Lazy::new(|| { static EXECUTION_PHRASE: LazyLock<String> = LazyLock::new(|| {
if get_utility_is_second_arg() { if get_utility_is_second_arg() {
ARGV.iter() ARGV.iter()
.take(2) .take(2)