mirror of
https://github.com/rust-lang/rust-analyzer
synced 2024-11-16 09:48:10 +00:00
Interned<T>
: Only hash the pointer
This commit is contained in:
parent
a0b50bcf1e
commit
b57462d60d
1 changed files with 8 additions and 2 deletions
|
@ -5,7 +5,7 @@
|
|||
use std::{
|
||||
collections::HashMap,
|
||||
fmt::{self, Debug},
|
||||
hash::{BuildHasherDefault, Hash},
|
||||
hash::{BuildHasherDefault, Hash, Hasher},
|
||||
ops::Deref,
|
||||
sync::Arc,
|
||||
};
|
||||
|
@ -20,7 +20,6 @@ type InternMap<T> = DashMap<Arc<T>, (), BuildHasherDefault<FxHasher>>;
|
|||
type Guard<T> =
|
||||
RwLockWriteGuard<'static, HashMap<Arc<T>, SharedValue<()>, BuildHasherDefault<FxHasher>>>;
|
||||
|
||||
#[derive(Hash)]
|
||||
pub struct Interned<T: Internable + ?Sized> {
|
||||
arc: Arc<T>,
|
||||
}
|
||||
|
@ -137,6 +136,13 @@ impl PartialEq for Interned<str> {
|
|||
|
||||
impl Eq for Interned<str> {}
|
||||
|
||||
impl<T: Internable + ?Sized> Hash for Interned<T> {
|
||||
fn hash<H: Hasher>(&self, state: &mut H) {
|
||||
// NOTE: Cast disposes vtable pointer / slice/str length.
|
||||
state.write_usize(Arc::as_ptr(&self.arc) as *const () as usize)
|
||||
}
|
||||
}
|
||||
|
||||
impl<T: Internable + ?Sized> AsRef<T> for Interned<T> {
|
||||
#[inline]
|
||||
fn as_ref(&self) -> &T {
|
||||
|
|
Loading…
Reference in a new issue