diff --git a/src/config/hashing.rs b/src/config/hashing.rs index c11f7626..41bfa837 100644 --- a/src/config/hashing.rs +++ b/src/config/hashing.rs @@ -98,7 +98,7 @@ fn hokmalock(address: usize) -> &'static HokmaLock { #[must_use] struct SusLock where - T: 'static + Copy, + T: 'static, { initialized: AtomicBool, data: UnsafeCell>, @@ -107,7 +107,7 @@ where impl SusLock where - T: 'static + Copy, + T: 'static, { #[inline] pub const fn new() -> SusLock { @@ -119,14 +119,14 @@ where } #[must_use] - pub fn get(&self) -> Option { + pub fn get(&self) -> Option<&'static T> { if self.initialized.load(Ordering::SeqCst) { let hokma = hokmalock(unsafe { mem::transmute(self.data.get()) }); // we forgo the optimistic read, because we don't really care let guard = hokma.write(); let val = { let cast: *const T = self.data.get().cast(); - unsafe { cast.read() } + unsafe { mem::transmute::<*const T, &'static T>(cast) } }; guard.the_price_of_silence(); Some(val) @@ -136,9 +136,9 @@ where } #[must_use] - pub fn get_or_init(&self, f: impl FnOnce() -> T) -> Option { - let value = f(); + pub fn get_or_init(&self, f: impl FnOnce() -> T) -> Option<&'static T> { if !self.initialized.load(Ordering::SeqCst) { + let value = f(); self.initialized.store(true, Ordering::SeqCst); let hokma = hokmalock(unsafe { mem::transmute(self.data.get()) }); hokma.write(); @@ -216,6 +216,9 @@ pub fn set_ahash_seed(new_seed: Option<[u64; 4]>) -> Result<(), Option<[u64; 4]> /// See [`set_rhai_ahash_seed`] for more. #[inline] #[must_use] -pub fn get_ahash_seed() -> Option<[u64; 4]> { - AHASH_SEED.get_or_init(|| hashing_env::AHASH_SEED).flatten() +pub fn get_ahash_seed() -> &Option<[u64; 4]> { + match AHASH_SEED.get_or_init(|| hashing_env::AHASH_SEED) { + Some(ash) => ash, + None => None, + } } diff --git a/src/func/hashing.rs b/src/func/hashing.rs index 2b457c4d..83b2fed1 100644 --- a/src/func/hashing.rs +++ b/src/func/hashing.rs @@ -79,7 +79,7 @@ impl BuildHasher for StraightHasherBuilder { pub fn get_hasher() -> ahash::AHasher { match config::hashing::get_ahash_seed() { Some([seed1, seed2, seed3, seed4]) if seed1 | seed2 | seed3 | seed4 != 0 => { - ahash::RandomState::with_seeds(seed1, seed2, seed3, seed4).build_hasher() + ahash::RandomState::with_seeds(*seed1, *seed2, *seed3, *seed4).build_hasher() } _ => ahash::AHasher::default(), }