From 0da313eb8495c02d4c2d216f1074ec1e0a062550 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Bennet=20Ble=C3=9Fmann?= Date: Thu, 25 Jul 2024 18:58:29 +0200 Subject: [PATCH] use a OnceLock static for LIBRARIES instead of thread_local! static --- src/machine/mod.rs | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/src/machine/mod.rs b/src/machine/mod.rs index 12170e39..1726ae5b 100644 --- a/src/machine/mod.rs +++ b/src/machine/mod.rs @@ -120,23 +120,25 @@ fn current_dir() -> PathBuf { mod libraries { use indexmap::IndexMap; + use std::sync::OnceLock; - std::thread_local! { - static LIBRARIES: IndexMap<&'static str, &'static str> = { + fn libraries() -> &'static IndexMap<&'static str, &'static str> { + static LIBRARIES: OnceLock> = OnceLock::new(); + LIBRARIES.get_or_init(|| { let mut m = IndexMap::new(); include!(concat!(env!("OUT_DIR"), "/libraries.rs")); m - } + }) } pub(crate) fn contains(name: &str) -> bool { - LIBRARIES.with(|libs| libs.contains_key(name)) + libraries().contains_key(name) } pub(crate) fn get(name: &str) -> Option<&'static str> { - LIBRARIES.with(|libs| libs.get(name).copied()) + libraries().get(name).copied() } } -- 2.54.0