aboutsummaryrefslogtreecommitdiff
path: root/crates/hir_def/src/intern.rs
diff options
context:
space:
mode:
authorJonas Schievink <[email protected]>2021-04-05 16:07:53 +0100
committerJonas Schievink <[email protected]>2021-04-05 16:07:53 +0100
commitb57462d60dbebedcfac00544d5ff1592c5117c1f (patch)
tree7b9b9b11ebf404cd6f2da12a9968b0218ceef07c /crates/hir_def/src/intern.rs
parenta0b50bcf1e18c5d909e8791e06284b9787076e8b (diff)
`Interned<T>`: Only hash the pointer
Diffstat (limited to 'crates/hir_def/src/intern.rs')
-rw-r--r--crates/hir_def/src/intern.rs10
1 files changed, 8 insertions, 2 deletions
diff --git a/crates/hir_def/src/intern.rs b/crates/hir_def/src/intern.rs
index 0d5419be5..abc304ef0 100644
--- a/crates/hir_def/src/intern.rs
+++ b/crates/hir_def/src/intern.rs
@@ -5,7 +5,7 @@
5use std::{ 5use std::{
6 collections::HashMap, 6 collections::HashMap,
7 fmt::{self, Debug}, 7 fmt::{self, Debug},
8 hash::{BuildHasherDefault, Hash}, 8 hash::{BuildHasherDefault, Hash, Hasher},
9 ops::Deref, 9 ops::Deref,
10 sync::Arc, 10 sync::Arc,
11}; 11};
@@ -20,7 +20,6 @@ type InternMap<T> = DashMap<Arc<T>, (), BuildHasherDefault<FxHasher>>;
20type Guard<T> = 20type Guard<T> =
21 RwLockWriteGuard<'static, HashMap<Arc<T>, SharedValue<()>, BuildHasherDefault<FxHasher>>>; 21 RwLockWriteGuard<'static, HashMap<Arc<T>, SharedValue<()>, BuildHasherDefault<FxHasher>>>;
22 22
23#[derive(Hash)]
24pub struct Interned<T: Internable + ?Sized> { 23pub struct Interned<T: Internable + ?Sized> {
25 arc: Arc<T>, 24 arc: Arc<T>,
26} 25}
@@ -137,6 +136,13 @@ impl PartialEq for Interned<str> {
137 136
138impl Eq for Interned<str> {} 137impl Eq for Interned<str> {}
139 138
139impl<T: Internable + ?Sized> Hash for Interned<T> {
140 fn hash<H: Hasher>(&self, state: &mut H) {
141 // NOTE: Cast disposes vtable pointer / slice/str length.
142 state.write_usize(Arc::as_ptr(&self.arc) as *const () as usize)
143 }
144}
145
140impl<T: Internable + ?Sized> AsRef<T> for Interned<T> { 146impl<T: Internable + ?Sized> AsRef<T> for Interned<T> {
141 #[inline] 147 #[inline]
142 fn as_ref(&self) -> &T { 148 fn as_ref(&self) -> &T {