From 1aec76a6e630edc8529faeb5a5dce514b67780dd Mon Sep 17 00:00:00 2001 From: Ben Pfaff Date: Tue, 17 Jun 2025 16:12:54 -0700 Subject: [PATCH] get rid of lazy_static --- rust/Cargo.lock | 7 ------- rust/pspp/Cargo.toml | 1 - rust/pspp/build.rs | 15 ++++++--------- rust/pspp/src/macros.rs | 14 ++++++-------- rust/pspp/src/sys/encoding.rs | 8 ++++---- 5 files changed, 16 insertions(+), 29 deletions(-) diff --git a/rust/Cargo.lock b/rust/Cargo.lock index 44608da21e..254f167ca3 100644 --- a/rust/Cargo.lock +++ b/rust/Cargo.lock @@ -1124,12 +1124,6 @@ dependencies = [ "wasm-bindgen", ] -[[package]] -name = "lazy_static" -version = "1.5.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bbd2bcb4c963f2ddae06a2efc7e9f3591312473c50c6685e1f298068316e66fe" - [[package]] name = "libc" version = "0.2.172" @@ -1586,7 +1580,6 @@ dependencies = [ "hexplay", "indexmap", "itertools", - "lazy_static", "libc", "libm", "ndarray", diff --git a/rust/pspp/Cargo.toml b/rust/pspp/Cargo.toml index 038d467bc2..731595c284 100644 --- a/rust/pspp/Cargo.toml +++ b/rust/pspp/Cargo.toml @@ -10,7 +10,6 @@ clap = { version = "4.1.7", features = ["derive", "wrap_help"] } encoding_rs = "0.8.32" flate2 = "1.0.26" hexplay = "0.2.1" -lazy_static = "1.4.0" num = "0.4.0" ordered-float = "3.7.0" thiserror = "1.0" diff --git a/rust/pspp/build.rs b/rust/pspp/build.rs index 7805bc2895..240e4af422 100644 --- a/rust/pspp/build.rs +++ b/rust/pspp/build.rs @@ -96,12 +96,10 @@ fn write_output( file.write_all( "\ -use lazy_static::lazy_static; use std::collections::HashMap; -lazy_static! { - static ref CODEPAGE_NUMBER_TO_NAME: HashMap = { - let mut map = HashMap::new(); +static CODEPAGE_NUMBER_TO_NAME: LazyLock> = LazyLock::new(|| { + let mut map = HashMap::new(); " .as_bytes(), )?; @@ -113,10 +111,10 @@ lazy_static! { } file.write_all( " map - }; +}); - static ref CODEPAGE_NAME_TO_NUMBER: HashMap<&'static str, u32> = { - let mut map = HashMap::new(); +static CODEPAGE_NAME_TO_NUMBER: LazyLock> = LazyLock::new(|| { + let mut map = HashMap::new(); " .as_bytes(), )?; @@ -142,8 +140,7 @@ lazy_static! { } file.write_all( " map - }; -} +}); " .as_bytes(), )?; diff --git a/rust/pspp/src/macros.rs b/rust/pspp/src/macros.rs index b2bc3f06fb..2d29549640 100644 --- a/rust/pspp/src/macros.rs +++ b/rust/pspp/src/macros.rs @@ -1,5 +1,4 @@ #![allow(dead_code)] -use lazy_static::lazy_static; use num::Integer; use std::{ cell::RefCell, @@ -8,6 +7,7 @@ use std::{ mem::take, num::NonZeroUsize, ops::RangeInclusive, + sync::LazyLock, }; use thiserror::Error as ThisError; use unicase::UniCase; @@ -824,9 +824,7 @@ fn macro_keywords() -> HashSet { } fn is_macro_keyword(s: &Identifier) -> bool { - lazy_static! { - static ref KEYWORDS: HashSet = macro_keywords(); - } + static KEYWORDS: LazyLock> = LazyLock::new(macro_keywords); KEYWORDS.contains(s) } @@ -1102,8 +1100,8 @@ impl Expander<'_> { } } } - lazy_static! { - static ref MACRO_FUNCTIONS: [MacroFunction; 11] = [ + static MACRO_FUNCTIONS: LazyLock<[MacroFunction; 11]> = LazyLock::new(|| { + [ MacroFunction::new("!BLANKS", 1..=1, Expander::expand_blanks), MacroFunction::new("!CONCAT", 1..=usize::MAX, Expander::expand_concat), MacroFunction::new("!HEAD", 1..=1, Expander::expand_head), @@ -1115,8 +1113,8 @@ impl Expander<'_> { MacroFunction::new("!UNQUOTE", 1..=1, Expander::expand_unquote), MacroFunction::new("!UPCASE", 1..=1, Expander::expand_upcase), MacroFunction::new("!EVAL", 1..=1, Expander::expand_eval), - ]; - } + ] + }); let function = MACRO_FUNCTIONS.iter().find(|mf| &mf.name == name)?; diff --git a/rust/pspp/src/sys/encoding.rs b/rust/pspp/src/sys/encoding.rs index 7baf427a1e..26c1657f88 100644 --- a/rust/pspp/src/sys/encoding.rs +++ b/rust/pspp/src/sys/encoding.rs @@ -1,3 +1,5 @@ +use std::sync::LazyLock; + use crate::locale_charset::locale_charset; use encoding_rs::{Encoding, UTF_8}; @@ -27,10 +29,8 @@ pub enum Error { } pub fn default_encoding() -> &'static Encoding { - lazy_static! { - static ref DEFAULT_ENCODING: &'static Encoding = - Encoding::for_label(locale_charset().as_bytes()).unwrap_or(UTF_8); - } + static DEFAULT_ENCODING: LazyLock<&'static Encoding> = + LazyLock::new(|| Encoding::for_label(locale_charset().as_bytes()).unwrap_or(UTF_8)); &DEFAULT_ENCODING } -- 2.30.2