Skip to content

Commit e177f7a

Browse files
committed
Remove once_cell dependency & use LazyLock
1 parent 0f9b36b commit e177f7a

File tree

9 files changed

+15
-27
lines changed

9 files changed

+15
-27
lines changed

Cargo.lock

Lines changed: 0 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -314,7 +314,6 @@ num-bigint = "0.4.4"
314314
num-prime = "0.4.4"
315315
num-traits = "0.2.19"
316316
number_prefix = "0.4"
317-
once_cell = "1.19.0"
318317
onig = { version = "~6.4", default-features = false }
319318
parse_datetime = "0.8.0"
320319
phf = "0.11.2"
@@ -366,7 +365,6 @@ uu_base32 = { version = "0.0.29", path = "src/uu/base32" }
366365

367366
[dependencies]
368367
clap = { workspace = true }
369-
once_cell = { workspace = true }
370368
uucore = { workspace = true }
371369
clap_complete = { workspace = true }
372370
clap_mangen = { workspace = true }

src/uu/ls/Cargo.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ glob = { workspace = true }
2424
hostname = { workspace = true }
2525
lscolors = { workspace = true }
2626
number_prefix = { workspace = true }
27-
once_cell = { workspace = true }
2827
selinux = { workspace = true, optional = true }
2928
terminal_size = { workspace = true }
3029
uucore = { workspace = true, features = [

src/uu/ls/src/ls.rs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3057,7 +3057,7 @@ fn get_inode(metadata: &Metadata) -> String {
30573057
// Currently getpwuid is `linux` target only. If it's broken out into
30583058
// a posix-compliant attribute this can be updated...
30593059
#[cfg(unix)]
3060-
use once_cell::sync::Lazy;
3060+
use std::sync::LazyLock;
30613061
#[cfg(unix)]
30623062
use std::sync::Mutex;
30633063
#[cfg(unix)]
@@ -3066,7 +3066,8 @@ use uucore::fs::FileInformation;
30663066

30673067
#[cfg(unix)]
30683068
fn cached_uid2usr(uid: u32) -> String {
3069-
static UID_CACHE: Lazy<Mutex<HashMap<u32, String>>> = Lazy::new(|| Mutex::new(HashMap::new()));
3069+
static UID_CACHE: LazyLock<Mutex<HashMap<u32, String>>> =
3070+
LazyLock::new(|| Mutex::new(HashMap::new()));
30703071

30713072
let mut uid_cache = UID_CACHE.lock().unwrap();
30723073
uid_cache
@@ -3086,7 +3087,8 @@ fn display_uname(metadata: &Metadata, config: &Config) -> String {
30863087

30873088
#[cfg(all(unix, not(target_os = "redox")))]
30883089
fn cached_gid2grp(gid: u32) -> String {
3089-
static GID_CACHE: Lazy<Mutex<HashMap<u32, String>>> = Lazy::new(|| Mutex::new(HashMap::new()));
3090+
static GID_CACHE: LazyLock<Mutex<HashMap<u32, String>>> =
3091+
LazyLock::new(|| Mutex::new(HashMap::new()));
30903092

30913093
let mut gid_cache = GID_CACHE.lock().unwrap();
30923094
gid_cache

src/uucore/Cargo.toml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,6 @@ data-encoding = { version = "2.6", optional = true }
4545
data-encoding-macro = { version = "0.1.15", optional = true }
4646
z85 = { version = "3.0.5", optional = true }
4747
libc = { workspace = true, optional = true }
48-
once_cell = { workspace = true }
4948
os_display = "0.1.3"
5049

5150
digest = { workspace = true, optional = true }
@@ -68,7 +67,6 @@ xattr = { workspace = true, optional = true }
6867

6968
[dev-dependencies]
7069
clap = { workspace = true }
71-
once_cell = { workspace = true }
7270
tempfile = { workspace = true }
7371

7472
[target.'cfg(target_os = "windows")'.dependencies]

src/uucore/src/lib/features/backup_control.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -485,16 +485,15 @@ mod tests {
485485
use super::*;
486486
// Required to instantiate mutex in shared context
487487
use clap::Command;
488-
use once_cell::sync::Lazy;
489-
use std::sync::Mutex;
488+
use std::sync::{LazyLock, Mutex};
490489

491490
// The mutex is required here as by default all tests are run as separate
492491
// threads under the same parent process. As environment variables are
493492
// specific to processes (and thus shared among threads), data races *will*
494493
// occur if no precautions are taken. Thus we have all tests that rely on
495494
// environment variables lock this empty mutex to ensure they don't access
496495
// it concurrently.
497-
static TEST_MUTEX: Lazy<Mutex<()>> = Lazy::new(|| Mutex::new(()));
496+
static TEST_MUTEX: LazyLock<Mutex<()>> = LazyLock::new(|| Mutex::new(()));
498497

499498
// Environment variable for "VERSION_CONTROL"
500499
static ENV_VERSION_CONTROL: &str = "VERSION_CONTROL";

src/uucore/src/lib/features/entries.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -43,9 +43,7 @@ use std::io::Error as IOError;
4343
use std::io::ErrorKind;
4444
use std::io::Result as IOResult;
4545
use std::ptr;
46-
use std::sync::Mutex;
47-
48-
use once_cell::sync::Lazy;
46+
use std::sync::{LazyLock, Mutex};
4947

5048
extern "C" {
5149
/// From: `<https://man7.org/linux/man-pages/man3/getgrouplist.3.html>`
@@ -276,7 +274,7 @@ pub trait Locate<K> {
276274
// to, so we must copy all the data we want before releasing the lock.
277275
// (Technically we must also ensure that the raw functions aren't being called
278276
// anywhere else in the program.)
279-
static PW_LOCK: Lazy<Mutex<()>> = Lazy::new(|| Mutex::new(()));
277+
static PW_LOCK: LazyLock<Mutex<()>> = LazyLock::new(|| Mutex::new(()));
280278

281279
macro_rules! f {
282280
($fnam:ident, $fid:ident, $t:ident, $st:ident) => {

src/uucore/src/lib/features/utmpx.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -304,7 +304,7 @@ impl Utmpx {
304304
// I believe the only technical memory unsafety that could happen is a data
305305
// race while copying the data out of the pointer returned by getutxent(), but
306306
// ordinary race conditions are also very much possible.
307-
static LOCK: Lazy<Mutex<()>> = Lazy::new(|| Mutex::new(()));
307+
static LOCK: LazyLock<Mutex<()>> = LazyLock::new(|| Mutex::new(()));
308308

309309
/// Iterator of login records
310310
pub struct UtmpxIter {

src/uucore/src/lib/lib.rs

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -115,16 +115,13 @@ use nix::sys::signal::{
115115
sigaction, SaFlags, SigAction, SigHandler::SigDfl, SigSet, Signal::SIGBUS, Signal::SIGSEGV,
116116
};
117117
use std::borrow::Cow;
118-
use std::ffi::OsStr;
119-
use std::ffi::OsString;
118+
use std::ffi::{OsStr, OsString};
120119
use std::io::{BufRead, BufReader};
121120
use std::iter;
122121
#[cfg(unix)]
123122
use std::os::unix::ffi::{OsStrExt, OsStringExt};
124123
use std::str;
125-
use std::sync::atomic::Ordering;
126-
127-
use once_cell::sync::Lazy;
124+
use std::sync::{atomic::Ordering, LazyLock};
128125

129126
/// 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.
130127
/// 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() {
194191

195192
// args_os() can be expensive to call, it copies all of argv before iterating.
196193
// So if we want only the first arg or so it's overkill. We cache it.
197-
static ARGV: Lazy<Vec<OsString>> = Lazy::new(|| wild::args_os().collect());
194+
static ARGV: LazyLock<Vec<OsString>> = LazyLock::new(|| wild::args_os().collect());
198195

199-
static UTIL_NAME: Lazy<String> = Lazy::new(|| {
196+
static UTIL_NAME: LazyLock<String> = LazyLock::new(|| {
200197
let base_index = usize::from(get_utility_is_second_arg());
201198
let is_man = usize::from(ARGV[base_index].eq("manpage"));
202199
let argv_index = base_index + is_man;
@@ -209,7 +206,7 @@ pub fn util_name() -> &'static str {
209206
&UTIL_NAME
210207
}
211208

212-
static EXECUTION_PHRASE: Lazy<String> = Lazy::new(|| {
209+
static EXECUTION_PHRASE: LazyLock<String> = LazyLock::new(|| {
213210
if get_utility_is_second_arg() {
214211
ARGV.iter()
215212
.take(2)

0 commit comments

Comments
 (0)