From 76452956e4ee3be89a9da69cccadfb980b075049 Mon Sep 17 00:00:00 2001 From: Jonas Schievink Date: Fri, 2 Apr 2021 18:11:08 +0200 Subject: Split `Intern::drop` into hot and cold path --- crates/hir_def/src/intern.rs | 39 +++++++++++++++++++++++---------------- 1 file changed, 23 insertions(+), 16 deletions(-) (limited to 'crates/hir_def/src') diff --git a/crates/hir_def/src/intern.rs b/crates/hir_def/src/intern.rs index 18c8ab246..785d9e3c6 100644 --- a/crates/hir_def/src/intern.rs +++ b/crates/hir_def/src/intern.rs @@ -53,31 +53,38 @@ impl Interned { } impl Drop for Interned { + #[inline] fn drop(&mut self) { // When the last `Ref` is dropped, remove the object from the global map. if Arc::strong_count(&self.arc) == 2 { // Only `self` and the global map point to the object. - let storage = T::storage().get(); - let shard_idx = storage.determine_map(&self.arc); - let shard = &storage.shards()[shard_idx]; - let mut shard = shard.write(); + self.drop_slow(); + } + } +} + +impl Interned { + #[cold] + fn drop_slow(&mut self) { + let storage = T::storage().get(); + let shard_idx = storage.determine_map(&self.arc); + let shard = &storage.shards()[shard_idx]; + let mut shard = shard.write(); - // FIXME: avoid double lookup - let (arc, _) = - shard.get_key_value(&self.arc).expect("interned value removed prematurely"); + // FIXME: avoid double lookup + let (arc, _) = shard.get_key_value(&self.arc).expect("interned value removed prematurely"); - if Arc::strong_count(arc) != 2 { - // Another thread has interned another copy - return; - } + if Arc::strong_count(arc) != 2 { + // Another thread has interned another copy + return; + } - shard.remove(&self.arc); + shard.remove(&self.arc); - // Shrink the backing storage if the shard is less than 50% occupied. - if shard.len() * 2 < shard.capacity() { - shard.shrink_to_fit(); - } + // Shrink the backing storage if the shard is less than 50% occupied. + if shard.len() * 2 < shard.capacity() { + shard.shrink_to_fit(); } } } -- cgit v1.2.3