diff --git a/src/env/environment_impl.rs b/src/env/environment_impl.rs index f549f2380..010084bf2 100644 --- a/src/env/environment_impl.rs +++ b/src/env/environment_impl.rs @@ -24,15 +24,16 @@ use std::ops::{Deref, DerefMut}; use std::sync::{atomic::AtomicU64, atomic::Ordering, Arc, Mutex, MutexGuard}; -// Universal variables instance. -lazy_static! { - static ref UVARS: Mutex = Mutex::new(EnvUniversal::new()); -} - /// Getter for universal variables. /// This is typically initialized in env_init(), and is considered empty before then. pub fn uvars() -> MutexGuard<'static, EnvUniversal> { - UVARS.lock().unwrap() + use std::sync::OnceLock; + /// Universal variables instance. + static UVARS: OnceLock> = OnceLock::new(); + UVARS + .get_or_init(|| Mutex::new(EnvUniversal::new())) + .lock() + .unwrap() } /// Whether we were launched with no_config; in this case setting a uvar instead sets a global. diff --git a/src/env/var.rs b/src/env/var.rs index 9b83077aa..937362f99 100644 --- a/src/env/var.rs +++ b/src/env/var.rs @@ -2,7 +2,6 @@ use crate::signal::Signal; use crate::wchar::{wstr, WString, L}; use crate::wcstringutil::join_strings; use bitflags::bitflags; -use lazy_static::lazy_static; use libc::c_int; use std::collections::HashMap; use std::path::PathBuf; @@ -97,11 +96,6 @@ bitflags! { } } -// A shared, empty list. -lazy_static! { - static ref EMPTY_LIST: Arc> = Arc::new(Box::new([])); -} - /// EnvVar is an immutable value-type data structure representing the value of an environment /// variable. #[derive(Clone, Debug, Eq, PartialEq)] @@ -115,8 +109,13 @@ pub struct EnvVar { impl Default for EnvVar { fn default() -> Self { + use std::sync::OnceLock; + /// A shared read-only empty list. + static EMPTY_LIST: OnceLock>> = OnceLock::new(); + let empty_list = EMPTY_LIST.get_or_init(|| Arc::new(Box::new([]))); + EnvVar { - values: EMPTY_LIST.clone(), + values: Arc::clone(empty_list), flags: EnvVarFlags::empty(), } }