about summary refs log tree commit diff
diff options
context:
space:
mode:
authorCamille GILLOT <gillot.camille@gmail.com>2020-11-02 22:36:47 +0100
committerCamille GILLOT <gillot.camille@gmail.com>2021-08-22 01:06:19 +0200
commit0edc775b90a6892a37ec4d41f72417fc379e67db (patch)
tree93f58fe1ef26724f4fccafbe21722d1545a67070
parent5e35fadddb8b91f6f7d47fb19e635d1fb1b2a965 (diff)
downloadrust-0edc775b90a6892a37ec4d41f72417fc379e67db.tar.gz
rust-0edc775b90a6892a37ec4d41f72417fc379e67db.zip
Only clone key when needed.
-rw-r--r--compiler/rustc_query_system/src/query/plumbing.rs10
1 files changed, 6 insertions, 4 deletions
diff --git a/compiler/rustc_query_system/src/query/plumbing.rs b/compiler/rustc_query_system/src/query/plumbing.rs
index c3627910341..a21b0336934 100644
--- a/compiler/rustc_query_system/src/query/plumbing.rs
+++ b/compiler/rustc_query_system/src/query/plumbing.rs
@@ -495,7 +495,7 @@ where
         // promoted to the current session during
         // `try_mark_green()`, so we can ignore them here.
         let loaded = tcx.start_query(job.id, None, || {
-            try_load_from_disk_and_cache_in_memory(tcx, key.clone(), &dep_node, query, compute)
+            try_load_from_disk_and_cache_in_memory(tcx, &key, &dep_node, query, compute)
         });
         if let Some((result, dep_node_index)) = loaded {
             return job.complete(result, dep_node_index);
@@ -509,12 +509,13 @@ where
 
 fn try_load_from_disk_and_cache_in_memory<CTX, K, V>(
     tcx: CTX,
-    key: K,
+    key: &K,
     dep_node: &DepNode<CTX::DepKind>,
     query: &QueryVtable<CTX, K, V>,
     compute: fn(CTX::DepContext, K) -> V,
 ) -> Option<(V, DepNodeIndex)>
 where
+    K: Clone,
     CTX: QueryContext,
     V: Debug,
 {
@@ -527,7 +528,7 @@ where
     debug_assert!(tcx.dep_context().dep_graph().is_green(dep_node));
 
     // First we try to load the result from the on-disk cache.
-    let result = if query.cache_on_disk(tcx, &key, None) {
+    let result = if query.cache_on_disk(tcx, key, None) {
         let prof_timer = tcx.dep_context().profiler().incr_cache_loading();
         let result = query.try_load_from_disk(tcx, prev_dep_node_index);
         prof_timer.finish_with_query_invocation_id(dep_node_index.into());
@@ -559,7 +560,8 @@ where
         let prof_timer = tcx.dep_context().profiler().query_provider();
 
         // The dep-graph for this computation is already in-place.
-        let result = tcx.dep_context().dep_graph().with_ignore(|| compute(*tcx.dep_context(), key));
+        let result =
+            tcx.dep_context().dep_graph().with_ignore(|| compute(*tcx.dep_context(), key.clone()));
 
         prof_timer.finish_with_query_invocation_id(dep_node_index.into());