Skip to content

rustc: Preallocate when building the dep graph #44586

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Sep 17, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions src/librustc/dep_graph/query.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,10 @@ impl DepGraphQuery {
pub fn new(nodes: &[DepNode],
edges: &[(DepNode, DepNode)])
-> DepGraphQuery {
let mut graph = Graph::new();
let mut graph = Graph::with_capacity(nodes.len(), edges.len());
let mut indices = FxHashMap();
for node in nodes {
indices.insert(node.clone(), graph.next_node_index());
graph.add_node(node.clone());
indices.insert(node.clone(), graph.add_node(node.clone()));
}

for &(ref source, ref target) in edges {
Expand Down
7 changes: 7 additions & 0 deletions src/librustc_data_structures/graph/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,13 @@ impl<N: Debug, E: Debug> Graph<N, E> {
}
}

pub fn with_capacity(nodes: usize, edges: usize) -> Graph<N, E> {
Graph {
nodes: SnapshotVec::with_capacity(nodes),
edges: SnapshotVec::with_capacity(edges),
}
}

// # Simple accessors

#[inline]
Expand Down
7 changes: 7 additions & 0 deletions src/librustc_data_structures/snapshot_vec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,13 @@ impl<D: SnapshotVecDelegate> SnapshotVec<D> {
}
}

pub fn with_capacity(n: usize) -> SnapshotVec<D> {
SnapshotVec {
values: Vec::with_capacity(n),
undo_log: Vec::new(),
}
}

fn in_snapshot(&self) -> bool {
!self.undo_log.is_empty()
}
Expand Down