diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-17 12:02:58 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-17 12:02:58 +0000 |
commit | 698f8c2f01ea549d77d7dc3338a12e04c11057b9 (patch) | |
tree | 173a775858bd501c378080a10dca74132f05bc50 /compiler/rustc_hir/src/def_path_hash_map.rs | |
parent | Initial commit. (diff) | |
download | rustc-698f8c2f01ea549d77d7dc3338a12e04c11057b9.tar.xz rustc-698f8c2f01ea549d77d7dc3338a12e04c11057b9.zip |
Adding upstream version 1.64.0+dfsg1.upstream/1.64.0+dfsg1
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'compiler/rustc_hir/src/def_path_hash_map.rs')
-rw-r--r-- | compiler/rustc_hir/src/def_path_hash_map.rs | 37 |
1 files changed, 37 insertions, 0 deletions
diff --git a/compiler/rustc_hir/src/def_path_hash_map.rs b/compiler/rustc_hir/src/def_path_hash_map.rs new file mode 100644 index 000000000..8bfb47af2 --- /dev/null +++ b/compiler/rustc_hir/src/def_path_hash_map.rs @@ -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>; |