Move hashes from rustc_data_structure to rustc_hashes so they can be shared with rust-analyzer
This commit is contained in:
parent
1d7cf0ff40
commit
4cf21866e8
50 changed files with 152 additions and 67 deletions
|
@ -6,6 +6,7 @@ edition = "2021"
|
|||
[dependencies]
|
||||
# tidy-alphabetical-start
|
||||
indexmap = "2.0.0"
|
||||
rustc_hashes = { path = "../rustc_hashes" }
|
||||
smallvec = { version = "1.8.1", features = ["union", "may_dangle"] }
|
||||
thin-vec = "0.2.12"
|
||||
# tidy-alphabetical-end
|
||||
|
|
|
@ -10,6 +10,7 @@ use std::path;
|
|||
use std::rc::Rc;
|
||||
use std::sync::Arc;
|
||||
|
||||
use rustc_hashes::{Hash64, Hash128};
|
||||
use smallvec::{Array, SmallVec};
|
||||
use thin_vec::ThinVec;
|
||||
|
||||
|
@ -716,3 +717,31 @@ impl<D: Decoder, T: Decodable<D>> Decodable<D> for Arc<[T]> {
|
|||
vec.into()
|
||||
}
|
||||
}
|
||||
|
||||
impl<S: Encoder> Encodable<S> for Hash64 {
|
||||
#[inline]
|
||||
fn encode(&self, s: &mut S) {
|
||||
s.emit_raw_bytes(&self.as_u64().to_le_bytes());
|
||||
}
|
||||
}
|
||||
|
||||
impl<S: Encoder> Encodable<S> for Hash128 {
|
||||
#[inline]
|
||||
fn encode(&self, s: &mut S) {
|
||||
s.emit_raw_bytes(&self.as_u128().to_le_bytes());
|
||||
}
|
||||
}
|
||||
|
||||
impl<D: Decoder> Decodable<D> for Hash64 {
|
||||
#[inline]
|
||||
fn decode(d: &mut D) -> Self {
|
||||
Self::new(u64::from_le_bytes(d.read_raw_bytes(8).try_into().unwrap()))
|
||||
}
|
||||
}
|
||||
|
||||
impl<D: Decoder> Decodable<D> for Hash128 {
|
||||
#[inline]
|
||||
fn decode(d: &mut D) -> Self {
|
||||
Self::new(u128::from_le_bytes(d.read_raw_bytes(16).try_into().unwrap()))
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue