Skip to content

Commit b57462d

Browse files
Interned<T>: Only hash the pointer
1 parent a0b50bc commit b57462d

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

crates/hir_def/src/intern.rs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
use std::{
66
collections::HashMap,
77
fmt::{self, Debug},
8-
hash::{BuildHasherDefault, Hash},
8+
hash::{BuildHasherDefault, Hash, Hasher},
99
ops::Deref,
1010
sync::Arc,
1111
};
@@ -20,7 +20,6 @@ type InternMap<T> = DashMap<Arc<T>, (), BuildHasherDefault<FxHasher>>;
2020
type Guard<T> =
2121
RwLockWriteGuard<'static, HashMap<Arc<T>, SharedValue<()>, BuildHasherDefault<FxHasher>>>;
2222

23-
#[derive(Hash)]
2423
pub struct Interned<T: Internable + ?Sized> {
2524
arc: Arc<T>,
2625
}
@@ -137,6 +136,13 @@ impl PartialEq for Interned<str> {
137136

138137
impl Eq for Interned<str> {}
139138

139+
impl<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+
140146
impl<T: Internable + ?Sized> AsRef<T> for Interned<T> {
141147
#[inline]
142148
fn as_ref(&self) -> &T {

0 commit comments

Comments
 (0)