]> git.lizzy.rs Git - rust.git/blob - compiler/rustc_hir/src/def_path_hash_map.rs
Remove `HirId -> LocalDefId` map from HIR.
[rust.git] / compiler / rustc_hir / src / def_path_hash_map.rs
1 use rustc_data_structures::fingerprint::Fingerprint;
2 use rustc_span::def_id::{DefIndex, DefPathHash};
3
4 #[derive(Clone, Default)]
5 pub struct Config;
6
7 impl odht::Config for Config {
8     type Key = DefPathHash;
9     type Value = DefIndex;
10
11     type EncodedKey = [u8; 16];
12     type EncodedValue = [u8; 4];
13
14     type H = odht::UnHashFn;
15
16     #[inline]
17     fn encode_key(k: &DefPathHash) -> [u8; 16] {
18         k.0.to_le_bytes()
19     }
20
21     #[inline]
22     fn encode_value(v: &DefIndex) -> [u8; 4] {
23         v.as_u32().to_le_bytes()
24     }
25
26     #[inline]
27     fn decode_key(k: &[u8; 16]) -> DefPathHash {
28         DefPathHash(Fingerprint::from_le_bytes(*k))
29     }
30
31     #[inline]
32     fn decode_value(v: &[u8; 4]) -> DefIndex {
33         DefIndex::from_u32(u32::from_le_bytes(*v))
34     }
35 }
36
37 pub type DefPathHashMap = odht::HashTableOwned<Config>;