1
Fork 0
mirror of https://github.com/RGBCube/uutils-coreutils synced 2025-07-27 19:17:43 +00:00

Merge pull request #7405 from cakebaker/remove_once_cell

Remove `once_cell` dependency and use `LazyLock`
This commit is contained in:
Sylvestre Ledru 2025-03-05 11:34:40 +01:00 committed by GitHub
commit 15864bcac1
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
9 changed files with 15 additions and 27 deletions

3
Cargo.lock generated
View file

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

View file

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

View file

@ -24,7 +24,6 @@ glob = { workspace = true }
hostname = { workspace = true }
lscolors = { workspace = true }
number_prefix = { workspace = true }
once_cell = { workspace = true }
selinux = { workspace = true, optional = true }
terminal_size = { workspace = true }
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
// a posix-compliant attribute this can be updated...
#[cfg(unix)]
use once_cell::sync::Lazy;
use std::sync::LazyLock;
#[cfg(unix)]
use std::sync::Mutex;
#[cfg(unix)]
@ -3066,7 +3066,8 @@ use uucore::fs::FileInformation;
#[cfg(unix)]
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();
uid_cache
@ -3086,7 +3087,8 @@ fn display_uname(metadata: &Metadata, config: &Config) -> String {
#[cfg(all(unix, not(target_os = "redox")))]
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();
gid_cache

View file

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

View file

@ -485,8 +485,7 @@ mod tests {
use super::*;
// Required to instantiate mutex in shared context
use clap::Command;
use once_cell::sync::Lazy;
use std::sync::Mutex;
use std::sync::{LazyLock, Mutex};
// The mutex is required here as by default all tests are run as separate
// 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
// environment variables lock this empty mutex to ensure they don't access
// 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"
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::Result as IOResult;
use std::ptr;
use std::sync::Mutex;
use once_cell::sync::Lazy;
use std::sync::{LazyLock, Mutex};
extern "C" {
/// 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.
// (Technically we must also ensure that the raw functions aren't being called
// 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 {
($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
// race while copying the data out of the pointer returned by getutxent(), but
// 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
pub struct UtmpxIter {

View file

@ -115,16 +115,13 @@ use nix::sys::signal::{
sigaction, SaFlags, SigAction, SigHandler::SigDfl, SigSet, Signal::SIGBUS, Signal::SIGSEGV,
};
use std::borrow::Cow;
use std::ffi::OsStr;
use std::ffi::OsString;
use std::ffi::{OsStr, OsString};
use std::io::{BufRead, BufReader};
use std::iter;
#[cfg(unix)]
use std::os::unix::ffi::{OsStrExt, OsStringExt};
use std::str;
use std::sync::atomic::Ordering;
use once_cell::sync::Lazy;
use std::sync::{atomic::Ordering, LazyLock};
/// 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.
@ -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.
// 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 is_man = usize::from(ARGV[base_index].eq("manpage"));
let argv_index = base_index + is_man;
@ -209,7 +206,7 @@ pub fn util_name() -> &'static str {
&UTIL_NAME
}
static EXECUTION_PHRASE: Lazy<String> = Lazy::new(|| {
static EXECUTION_PHRASE: LazyLock<String> = LazyLock::new(|| {
if get_utility_is_second_arg() {
ARGV.iter()
.take(2)