Use on-disk-hash-table format for DefPathHashMap in hir::definitions.

This commit is contained in:
Michael Woerister
2021-07-20 13:54:37 +02:00
parent 0debea1377
commit d0be27c8ec
7 changed files with 66 additions and 5 deletions

View File

@@ -0,0 +1,37 @@
use rustc_data_structures::fingerprint::Fingerprint;
use rustc_span::def_id::{DefIndex, DefPathHash};
#[derive(Clone, Default)]
pub struct Config;
impl odht::Config for Config {
type Key = DefPathHash;
type Value = DefIndex;
type EncodedKey = [u8; 16];
type EncodedValue = [u8; 4];
type H = odht::UnHashFn;
#[inline]
fn encode_key(k: &DefPathHash) -> [u8; 16] {
k.0.to_le_bytes()
}
#[inline]
fn encode_value(v: &DefIndex) -> [u8; 4] {
v.as_u32().to_le_bytes()
}
#[inline]
fn decode_key(k: &[u8; 16]) -> DefPathHash {
DefPathHash(Fingerprint::from_le_bytes(*k))
}
#[inline]
fn decode_value(v: &[u8; 4]) -> DefIndex {
DefIndex::from_u32(u32::from_le_bytes(*v))
}
}
pub type DefPathHashMap = odht::HashTableOwned<Config>;