rustc_query_system/dep_graph/
edges.rs1use std::hash::{Hash, Hasher};
2use std::ops::Deref;
3
4use smallvec::SmallVec;
5
6use crate::dep_graph::DepNodeIndex;
7
8#[derive(#[automatically_derived]
impl ::core::default::Default for EdgesVec {
#[inline]
fn default() -> EdgesVec {
EdgesVec {
max: ::core::default::Default::default(),
edges: ::core::default::Default::default(),
}
}
}Default, #[automatically_derived]
impl ::core::fmt::Debug for EdgesVec {
#[inline]
fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
::core::fmt::Formatter::debug_struct_field2_finish(f, "EdgesVec",
"max", &self.max, "edges", &&self.edges)
}
}Debug)]
9pub(crate) struct EdgesVec {
10 max: u32,
11 edges: SmallVec<[DepNodeIndex; 8]>,
12}
13
14impl Hash for EdgesVec {
15 #[inline]
16 fn hash<H: Hasher>(&self, hasher: &mut H) {
17 Hash::hash(&self.edges, hasher)
18 }
19}
20
21impl EdgesVec {
22 #[inline]
23 pub(crate) fn new() -> Self {
24 Self::default()
25 }
26
27 #[inline]
28 pub(crate) fn push(&mut self, edge: DepNodeIndex) {
29 self.max = self.max.max(edge.as_u32());
30 self.edges.push(edge);
31 }
32
33 #[inline]
34 pub(crate) fn max_index(&self) -> u32 {
35 self.max
36 }
37}
38
39impl Deref for EdgesVec {
40 type Target = [DepNodeIndex];
41
42 #[inline]
43 fn deref(&self) -> &Self::Target {
44 self.edges.as_slice()
45 }
46}
47
48impl FromIterator<DepNodeIndex> for EdgesVec {
49 #[inline]
50 fn from_iter<T>(iter: T) -> Self
51 where
52 T: IntoIterator<Item = DepNodeIndex>,
53 {
54 let mut vec = EdgesVec::new();
55 for index in iter {
56 vec.push(index)
57 }
58 vec
59 }
60}
61
62impl Extend<DepNodeIndex> for EdgesVec {
63 #[inline]
64 fn extend<T>(&mut self, iter: T)
65 where
66 T: IntoIterator<Item = DepNodeIndex>,
67 {
68 for elem in iter {
69 self.push(elem);
70 }
71 }
72}