Convert ShardedHashMap
to use hashbrown::HashTable
The `hash_raw_entry` feature has finished fcp-close, so the compiler should stop using it to allow its removal. Several `Sharded` maps were using raw entries to avoid re-hashing between shard and map lookup, and we can do that with `hashbrown::HashTable` instead.
This commit is contained in:
parent
9fb94b32df
commit
3b0c2585c8
10 changed files with 109 additions and 66 deletions
|
@ -2,8 +2,7 @@ use std::fmt::Debug;
|
|||
use std::hash::Hash;
|
||||
use std::sync::OnceLock;
|
||||
|
||||
use rustc_data_structures::fx::FxHashMap;
|
||||
use rustc_data_structures::sharded::{self, Sharded};
|
||||
use rustc_data_structures::sharded::ShardedHashMap;
|
||||
pub use rustc_data_structures::vec_cache::VecCache;
|
||||
use rustc_hir::def_id::LOCAL_CRATE;
|
||||
use rustc_index::Idx;
|
||||
|
@ -36,7 +35,7 @@ pub trait QueryCache: Sized {
|
|||
/// In-memory cache for queries whose keys aren't suitable for any of the
|
||||
/// more specialized kinds of cache. Backed by a sharded hashmap.
|
||||
pub struct DefaultCache<K, V> {
|
||||
cache: Sharded<FxHashMap<K, (V, DepNodeIndex)>>,
|
||||
cache: ShardedHashMap<K, (V, DepNodeIndex)>,
|
||||
}
|
||||
|
||||
impl<K, V> Default for DefaultCache<K, V> {
|
||||
|
@ -55,19 +54,14 @@ where
|
|||
|
||||
#[inline(always)]
|
||||
fn lookup(&self, key: &K) -> Option<(V, DepNodeIndex)> {
|
||||
let key_hash = sharded::make_hash(key);
|
||||
let lock = self.cache.lock_shard_by_hash(key_hash);
|
||||
let result = lock.raw_entry().from_key_hashed_nocheck(key_hash, key);
|
||||
|
||||
if let Some((_, value)) = result { Some(*value) } else { None }
|
||||
self.cache.get(key)
|
||||
}
|
||||
|
||||
#[inline]
|
||||
fn complete(&self, key: K, value: V, index: DepNodeIndex) {
|
||||
let mut lock = self.cache.lock_shard_by_value(&key);
|
||||
// We may be overwriting another value. This is all right, since the dep-graph
|
||||
// will check that the fingerprint matches.
|
||||
lock.insert(key, (value, index));
|
||||
self.cache.insert(key, (value, index));
|
||||
}
|
||||
|
||||
fn iter(&self, f: &mut dyn FnMut(&Self::Key, &Self::Value, DepNodeIndex)) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue