mirror of
https://github.com/roc-lang/roc.git
synced 2025-09-26 13:29:12 +00:00
Add LayoutInterner to LayoutCache
Adds a thread-local interner of layouts to LayoutCache, and updates all references appropriately. This is a bit suboptimal for single-threaded workloads that will look at creating layout caches again, like the REPL, but I think that's okay for now - since the global interner will be uncontested for those workloads, it should still be plenty fast to access the interner, even behind a lock.
This commit is contained in:
parent
9d170be5c7
commit
c5466810a4
19 changed files with 177 additions and 86 deletions
|
@ -181,6 +181,20 @@ impl<'a, K: Hash + Eq> Interner<'a, K> for ThreadLocalInterner<'a, K> {
|
|||
}
|
||||
}
|
||||
|
||||
impl<'a, K> SingleThreadedInterner<'a, K> {
|
||||
/// Promotes the [SingleThreadedInterner] back to a [GlobalInterner].
|
||||
///
|
||||
/// You should *only* use this if you need to go from a single-threaded to a concurrent context,
|
||||
/// or in a case where you explicitly need access to [ThreadLocalInterner]s.
|
||||
pub fn into_global(self) -> Arc<GlobalInterner<'a, K>> {
|
||||
let SingleThreadedInterner { map, vec } = self;
|
||||
Arc::new(GlobalInterner {
|
||||
map: Mutex::new(map),
|
||||
vec: RwLock::new(vec),
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a, K: Hash + Eq> Interner<'a, K> for SingleThreadedInterner<'a, K> {
|
||||
fn insert(&mut self, value: &'a K) -> Interned<K> {
|
||||
let hash = hash(value);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue