use crate::{ structures::Map, types::{FuncSig, SigIndex}, }; use hashbrown::HashMap; use lazy_static::lazy_static; use parking_lot::RwLock; use std::sync::Arc; lazy_static! { static ref GLOBAL_SIG_REGISTRY: RwLock = { let registry = GlobalSigRegistry { func_table: HashMap::new(), sig_assoc: Map::new(), }; RwLock::new(registry) }; } struct GlobalSigRegistry { func_table: HashMap, SigIndex>, sig_assoc: Map>, } #[derive(Debug)] pub struct SigRegistry; impl SigRegistry { pub fn lookup_sig_index(&self, func_sig: Sig) -> SigIndex where Sig: Into>, { let func_sig = func_sig.into(); let mut global = (*GLOBAL_SIG_REGISTRY).write(); let global = &mut *global; let func_table = &mut global.func_table; let sig_assoc = &mut global.sig_assoc; let sig_index = *func_table .entry(Arc::clone(&func_sig)) .or_insert_with(|| sig_assoc.push(func_sig)); sig_index } pub fn lookup_signature(&self, sig_index: SigIndex) -> Arc { let global = (*GLOBAL_SIG_REGISTRY).read(); Arc::clone(&global.sig_assoc[sig_index]) } }