compute database-key-index for interned fields

This commit is contained in:
Niko Matsakis 2020-06-30 15:18:32 +00:00
parent a45087a322
commit 29b6b833d1

View file

@ -7,7 +7,7 @@ use crate::plumbing::QueryStorageMassOps;
use crate::plumbing::QueryStorageOps; use crate::plumbing::QueryStorageOps;
use crate::revision::Revision; use crate::revision::Revision;
use crate::Query; use crate::Query;
use crate::{CycleError, Database, DiscardIf, SweepStrategy}; use crate::{CycleError, Database, DatabaseKeyIndex, DiscardIf, SweepStrategy};
use crossbeam_utils::atomic::AtomicCell; use crossbeam_utils::atomic::AtomicCell;
use parking_lot::RwLock; use parking_lot::RwLock;
use rustc_hash::FxHashMap; use rustc_hash::FxHashMap;
@ -27,6 +27,7 @@ where
Q::Value: InternKey, Q::Value: InternKey,
DB: Database, DB: Database,
{ {
group_index: u16,
tables: RwLock<InternTables<Q::Key>>, tables: RwLock<InternTables<Q::Key>>,
} }
@ -97,6 +98,9 @@ struct Slot<K> {
/// set to None if gc'd. /// set to None if gc'd.
index: InternId, index: InternId,
/// DatabaseKeyIndex for this slot.
database_key_index: DatabaseKeyIndex,
/// Value that was interned. /// Value that was interned.
value: K, value: K,
@ -222,8 +226,14 @@ where
}; };
let create_slot = |index: InternId| { let create_slot = |index: InternId| {
let database_key_index = DatabaseKeyIndex {
group_index: self.group_index,
query_index: Q::QUERY_INDEX,
key_index: index.as_u32(),
};
Arc::new(Slot { Arc::new(Slot {
index, index,
database_key_index,
value: owned_key2, value: owned_key2,
interned_at: revision_now, interned_at: revision_now,
accessed_at: AtomicCell::new(Some(revision_now)), accessed_at: AtomicCell::new(Some(revision_now)),
@ -284,8 +294,9 @@ where
Q::Value: InternKey, Q::Value: InternKey,
DB: Database, DB: Database,
{ {
fn new(_group_index: u16) -> Self { fn new(group_index: u16) -> Self {
InternedStorage { InternedStorage {
group_index,
tables: RwLock::new(InternTables::default()), tables: RwLock::new(InternTables::default()),
} }
} }