about summary refs log tree commit diff
diff options
context:
space:
mode:
authorkennytm <kennytm@gmail.com>2018-03-14 23:26:28 +0800
committerkennytm <kennytm@gmail.com>2018-03-15 00:15:55 +0800
commit6639b60ec6f5479d2fac655e67d14d5a7a8adb27 (patch)
tree764a9e07e255468018ccdc5063181fa278ed0ece
parent55e5ba3b81056bc88109aa9386503e21eae30808 (diff)
parent2f2e17341c171c847c201516bec9bf2234704000 (diff)
downloadrust-6639b60ec6f5479d2fac655e67d14d5a7a8adb27.tar.gz
rust-6639b60ec6f5479d2fac655e67d14d5a7a8adb27.zip
Rollup merge of #48966 - retep007:hir-fingerprint-optimization, r=michaelwoerister
Speed up SVH computation by using Fingerprint::combine()

Fix #47297
-rw-r--r--src/librustc/hir/map/collector.rs20
1 files changed, 12 insertions, 8 deletions
diff --git a/src/librustc/hir/map/collector.rs b/src/librustc/hir/map/collector.rs
index 3c523f5633e..f77275926eb 100644
--- a/src/librustc/hir/map/collector.rs
+++ b/src/librustc/hir/map/collector.rs
@@ -13,6 +13,7 @@ use dep_graph::{DepGraph, DepKind, DepNodeIndex};
 use hir::def_id::{LOCAL_CRATE, CrateNum};
 use hir::intravisit::{Visitor, NestedVisitorMap};
 use hir::svh::Svh;
+use ich::Fingerprint;
 use middle::cstore::CrateStore;
 use session::CrateDisambiguator;
 use std::iter::repeat;
@@ -121,21 +122,24 @@ impl<'a, 'hir> NodeCollector<'a, 'hir> {
         collector
     }
 
-    pub(super) fn finalize_and_compute_crate_hash(self,
+    pub(super) fn finalize_and_compute_crate_hash(mut self,
                                                   crate_disambiguator: CrateDisambiguator,
                                                   cstore: &dyn CrateStore,
                                                   codemap: &CodeMap,
                                                   commandline_args_hash: u64)
                                                   -> (Vec<MapEntry<'hir>>, Svh) {
-        let mut node_hashes: Vec<_> = self
+        self
             .hir_body_nodes
-            .iter()
-            .map(|&(def_path_hash, dep_node_index)| {
-                (def_path_hash, self.dep_graph.fingerprint_of(dep_node_index))
-            })
-            .collect();
+            .sort_unstable_by(|&(ref d1, _), &(ref d2, _)| d1.cmp(d2));
 
-        node_hashes.sort_unstable_by(|&(ref d1, _), &(ref d2, _)| d1.cmp(d2));
+        let node_hashes = self
+            .hir_body_nodes
+            .iter()
+            .fold(Fingerprint::ZERO, |fingerprint , &(def_path_hash, dep_node_index)| {
+                fingerprint.combine(
+                    def_path_hash.0.combine(self.dep_graph.fingerprint_of(dep_node_index))
+                )
+            });
 
         let mut upstream_crates: Vec<_> = cstore.crates_untracked().iter().map(|&cnum| {
             let name = cstore.crate_name_untracked(cnum).as_str();