Replace lazy_static with once_cell

This commit is contained in:
Jamie Quigley 2022-07-12 14:08:18 +01:00
parent 37b754f462
commit 1a270361c0
No known key found for this signature in database
GPG key ID: 8E8FF66E2AE8D970
9 changed files with 12 additions and 37 deletions

4
Cargo.lock generated
View file

@ -327,9 +327,9 @@ dependencies = [
"filetime",
"glob",
"hex-literal",
"lazy_static",
"libc",
"nix",
"once_cell",
"phf",
"phf_codegen",
"pretty_assertions",
@ -2525,7 +2525,6 @@ dependencies = [
"chrono",
"clap 3.1.18",
"glob",
"lazy_static",
"lscolors",
"number_prefix",
"once_cell",
@ -3110,7 +3109,6 @@ dependencies = [
"dns-lookup",
"dunce",
"itertools",
"lazy_static",
"libc",
"nix",
"once_cell",

View file

@ -261,11 +261,11 @@ uudoc = [ "zip" ]
[dependencies]
clap = { version = "3.1", features = ["wrap_help", "cargo"] }
clap_complete = "3.1"
once_cell = "1.13.0"
phf = "0.10.1"
lazy_static = { version="1.3" }
selinux = { version="0.2", optional = true }
textwrap = { version="0.15", features=["terminal_size"] }
uucore = { version=">=0.0.11", package="uucore", path="src/uucore" }
selinux = { version="0.2", optional = true }
zip = { version = "0.6.0", optional=true, default_features=false, features=["deflate"] }
# * uutils
uu_test = { optional=true, version="0.0.14", package="uu_test", path="src/uu/test" }

View file

@ -28,9 +28,6 @@ once_cell = "1.13.0"
atty = "0.2"
selinux = { version="0.2", optional = true }
[target.'cfg(unix)'.dependencies]
lazy_static = "1.4.0"
[[bin]]
name = "ls"
path = "src/main.rs"

View file

@ -9,9 +9,6 @@
#[macro_use]
extern crate uucore;
#[cfg(unix)]
#[macro_use]
extern crate lazy_static;
use clap::{crate_version, Arg, Command};
use glob::Pattern;
@ -2251,6 +2248,8 @@ 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;
#[cfg(unix)]
use std::sync::Mutex;
#[cfg(unix)]
use uucore::entries;
@ -2258,9 +2257,7 @@ use uucore::quoting_style;
#[cfg(unix)]
fn cached_uid2usr(uid: u32) -> String {
lazy_static! {
static ref UID_CACHE: Mutex<HashMap<u32, String>> = Mutex::new(HashMap::new());
}
static UID_CACHE: Lazy<Mutex<HashMap<u32, String>>> = Lazy::new(|| Mutex::new(HashMap::new()));
let mut uid_cache = UID_CACHE.lock().unwrap();
uid_cache
@ -2280,9 +2277,7 @@ fn display_uname(metadata: &Metadata, config: &Config) -> String {
#[cfg(all(unix, not(target_os = "redox")))]
fn cached_gid2grp(gid: u32) -> String {
lazy_static! {
static ref GID_CACHE: Mutex<HashMap<u32, String>> = Mutex::new(HashMap::new());
}
static GID_CACHE: Lazy<Mutex<HashMap<u32, String>>> = Lazy::new(|| Mutex::new(HashMap::new()));
let mut gid_cache = GID_CACHE.lock().unwrap();
gid_cache

View file

@ -41,7 +41,7 @@ nix = { version = "0.24.1", optional = true, default-features = false, features
[dev-dependencies]
clap = "3.1"
lazy_static = "1.3"
once_cell = "1.13"
[target.'cfg(target_os = "windows")'.dependencies]
winapi = { version = "0.3", features = ["errhandlingapi", "fileapi", "handleapi", "winerror"] }

View file

@ -447,7 +447,7 @@ mod tests {
use std::env;
// Required to instantiate mutex in shared context
use clap::Command;
use lazy_static::lazy_static;
use once_cell::sync::Lazy;
use std::sync::Mutex;
// The mutex is required here as by default all tests are run as separate
@ -456,9 +456,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.
lazy_static! {
static ref TEST_MUTEX: Mutex<()> = Mutex::new(());
}
static TEST_MUTEX: Lazy<Mutex<()>> = Lazy::new(|| Mutex::new(()));
// Environment variable for "VERSION_CONTROL"
static ENV_VERSION_CONTROL: &str = "VERSION_CONTROL";

View file

@ -1,4 +1,5 @@
use crate::common::util::*;
use once_cell::sync::Lazy;
use std::fs::{metadata, set_permissions, OpenOptions, Permissions};
use std::os::unix::fs::{OpenOptionsExt, PermissionsExt};
use std::sync::Mutex;
@ -11,9 +12,7 @@ use self::libc::umask;
static TEST_FILE: &str = "file";
static REFERENCE_FILE: &str = "reference";
static REFERENCE_PERMS: u32 = 0o247;
lazy_static! {
static ref UMASK_MUTEX: Mutex<()> = Mutex::new(());
}
static UMASK_MUTEX: Lazy<Mutex<()>> = Lazy::new(|| Mutex::new(()));
struct TestCase {
args: Vec<&'static str>,

View file

@ -18,16 +18,9 @@ use std::os::unix::io::IntoRawFd;
use std::path::Path;
#[cfg(not(windows))]
use std::path::PathBuf;
#[cfg(not(windows))]
use std::sync::Mutex;
use std::thread::sleep;
use std::time::Duration;
#[cfg(not(windows))]
lazy_static! {
static ref UMASK_MUTEX: Mutex<()> = Mutex::new(());
}
const LONG_ARGS: &[&str] = &[
"-l",
"--long",

View file

@ -1,11 +1,6 @@
#[macro_use]
mod common;
#[allow(unused_imports)]
#[cfg(unix)]
#[macro_use]
extern crate lazy_static;
#[cfg(unix)]
extern crate rust_users;