From 63cfcbe7a7745b276de58ec92e0141b958c44feb Mon Sep 17 00:00:00 2001 From: Nathan Reiner Date: Sat, 10 Aug 2024 19:06:46 +0200 Subject: use unsafe blocks instead of mutexes --- src/config/mod.rs | 18 +++++------------- 1 file changed, 5 insertions(+), 13 deletions(-) (limited to 'src/config/mod.rs') diff --git a/src/config/mod.rs b/src/config/mod.rs index cc4154c..4aac0cf 100644 --- a/src/config/mod.rs +++ b/src/config/mod.rs @@ -1,11 +1,10 @@ -use std::sync::{RwLock, RwLockReadGuard, RwLockWriteGuard}; +use std::ptr::addr_of_mut; -use lazy_static::lazy_static; use mlua::{UserData, UserDataFields}; use self::{keymap::KeyMap, theme::Theme}; -pub mod constants; +pub mod env; pub mod theme; pub mod keymap; @@ -15,10 +14,6 @@ pub struct GlobalConfig { pub keymap: KeyMap, } -lazy_static! { - static ref GLOBAL_CONFIG: RwLock = RwLock::new(GlobalConfig::new()); -} - const DUMMY_CONFIG: GlobalConfig = GlobalConfig::new(); impl GlobalConfig { @@ -29,12 +24,9 @@ impl GlobalConfig { } } - pub fn instance() -> RwLockReadGuard<'static, Self> { - GLOBAL_CONFIG.read().unwrap() - } - - pub fn instance_mut() -> RwLockWriteGuard<'static, Self> { - GLOBAL_CONFIG.write().unwrap() + pub fn get() -> &'static mut Self { + static mut GLOBAL_CONFIG: GlobalConfig = GlobalConfig::new(); + unsafe { &mut *addr_of_mut!(GLOBAL_CONFIG) } } } -- cgit v1.2.3-70-g09d2