From: Bennet Bleßmann Date: Thu, 25 Jul 2024 16:58:29 +0000 (+0200) Subject: use a OnceLock static for LIBRARIES instead of thread_local! static X-Git-Tag: v0.10.0~126^2~3 X-Git-Url: https://git.sagredo.dev/?a=commitdiff_plain;h=0da313eb8495c02d4c2d216f1074ec1e0a062550;p=scryer-prolog.git use a OnceLock static for LIBRARIES instead of thread_local! static --- 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() } }