Skip to content

Commit 2f2e173

Browse files
committed
Speed up SVH computation by using Fingerprint::combine()
Fix #47297 r? @michaelwoerister
1 parent 063deba commit 2f2e173

File tree

1 file changed

+12
-8
lines changed

1 file changed

+12
-8
lines changed

src/librustc/hir/map/collector.rs

+12-8
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ use dep_graph::{DepGraph, DepKind, DepNodeIndex};
1313
use hir::def_id::{LOCAL_CRATE, CrateNum};
1414
use hir::intravisit::{Visitor, NestedVisitorMap};
1515
use hir::svh::Svh;
16+
use ich::Fingerprint;
1617
use middle::cstore::CrateStore;
1718
use session::CrateDisambiguator;
1819
use std::iter::repeat;
@@ -121,21 +122,24 @@ impl<'a, 'hir> NodeCollector<'a, 'hir> {
121122
collector
122123
}
123124

124-
pub(super) fn finalize_and_compute_crate_hash(self,
125+
pub(super) fn finalize_and_compute_crate_hash(mut self,
125126
crate_disambiguator: CrateDisambiguator,
126127
cstore: &CrateStore,
127128
codemap: &CodeMap,
128129
commandline_args_hash: u64)
129130
-> (Vec<MapEntry<'hir>>, Svh) {
130-
let mut node_hashes: Vec<_> = self
131+
self
131132
.hir_body_nodes
132-
.iter()
133-
.map(|&(def_path_hash, dep_node_index)| {
134-
(def_path_hash, self.dep_graph.fingerprint_of(dep_node_index))
135-
})
136-
.collect();
133+
.sort_unstable_by(|&(ref d1, _), &(ref d2, _)| d1.cmp(d2));
137134

138-
node_hashes.sort_unstable_by(|&(ref d1, _), &(ref d2, _)| d1.cmp(d2));
135+
let node_hashes = self
136+
.hir_body_nodes
137+
.iter()
138+
.fold(Fingerprint::ZERO, |fingerprint , &(def_path_hash, dep_node_index)| {
139+
fingerprint.combine(
140+
def_path_hash.0.combine(self.dep_graph.fingerprint_of(dep_node_index))
141+
)
142+
});
139143

140144
let mut upstream_crates: Vec<_> = cstore.crates_untracked().iter().map(|&cnum| {
141145
let name = cstore.crate_name_untracked(cnum).as_str();

0 commit comments

Comments
 (0)