Use a specialized varint + bitpacking scheme for DepGraph encoding
This commit is contained in:
60
compiler/rustc_query_system/src/dep_graph/edges.rs
Normal file
60
compiler/rustc_query_system/src/dep_graph/edges.rs
Normal file
@@ -0,0 +1,60 @@
|
||||
use crate::dep_graph::DepNodeIndex;
|
||||
use smallvec::SmallVec;
|
||||
use std::hash::{Hash, Hasher};
|
||||
use std::ops::Deref;
|
||||
|
||||
#[derive(Default, Debug)]
|
||||
pub struct EdgesVec {
|
||||
max: u32,
|
||||
edges: SmallVec<[DepNodeIndex; EdgesVec::INLINE_CAPACITY]>,
|
||||
}
|
||||
|
||||
impl Hash for EdgesVec {
|
||||
#[inline]
|
||||
fn hash<H: Hasher>(&self, hasher: &mut H) {
|
||||
Hash::hash(&self.edges, hasher)
|
||||
}
|
||||
}
|
||||
|
||||
impl EdgesVec {
|
||||
pub const INLINE_CAPACITY: usize = 8;
|
||||
|
||||
#[inline]
|
||||
pub fn new() -> Self {
|
||||
Self::default()
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn push(&mut self, edge: DepNodeIndex) {
|
||||
self.max = self.max.max(edge.as_u32());
|
||||
self.edges.push(edge);
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn max_index(&self) -> u32 {
|
||||
self.max
|
||||
}
|
||||
}
|
||||
|
||||
impl Deref for EdgesVec {
|
||||
type Target = [DepNodeIndex];
|
||||
|
||||
#[inline]
|
||||
fn deref(&self) -> &Self::Target {
|
||||
self.edges.as_slice()
|
||||
}
|
||||
}
|
||||
|
||||
impl FromIterator<DepNodeIndex> for EdgesVec {
|
||||
#[inline]
|
||||
fn from_iter<T>(iter: T) -> Self
|
||||
where
|
||||
T: IntoIterator<Item = DepNodeIndex>,
|
||||
{
|
||||
let mut vec = EdgesVec::new();
|
||||
for index in iter {
|
||||
vec.push(index)
|
||||
}
|
||||
vec
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user