Skip to content

Commit 0edc775

Browse files
committed
Only clone key when needed.
1 parent 5e35fad commit 0edc775

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

compiler/rustc_query_system/src/query/plumbing.rs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -495,7 +495,7 @@ where
495495
// promoted to the current session during
496496
// `try_mark_green()`, so we can ignore them here.
497497
let loaded = tcx.start_query(job.id, None, || {
498-
try_load_from_disk_and_cache_in_memory(tcx, key.clone(), &dep_node, query, compute)
498+
try_load_from_disk_and_cache_in_memory(tcx, &key, &dep_node, query, compute)
499499
});
500500
if let Some((result, dep_node_index)) = loaded {
501501
return job.complete(result, dep_node_index);
@@ -509,12 +509,13 @@ where
509509

510510
fn try_load_from_disk_and_cache_in_memory<CTX, K, V>(
511511
tcx: CTX,
512-
key: K,
512+
key: &K,
513513
dep_node: &DepNode<CTX::DepKind>,
514514
query: &QueryVtable<CTX, K, V>,
515515
compute: fn(CTX::DepContext, K) -> V,
516516
) -> Option<(V, DepNodeIndex)>
517517
where
518+
K: Clone,
518519
CTX: QueryContext,
519520
V: Debug,
520521
{
@@ -527,7 +528,7 @@ where
527528
debug_assert!(tcx.dep_context().dep_graph().is_green(dep_node));
528529

529530
// First we try to load the result from the on-disk cache.
530-
let result = if query.cache_on_disk(tcx, &key, None) {
531+
let result = if query.cache_on_disk(tcx, key, None) {
531532
let prof_timer = tcx.dep_context().profiler().incr_cache_loading();
532533
let result = query.try_load_from_disk(tcx, prev_dep_node_index);
533534
prof_timer.finish_with_query_invocation_id(dep_node_index.into());
@@ -559,7 +560,8 @@ where
559560
let prof_timer = tcx.dep_context().profiler().query_provider();
560561

561562
// The dep-graph for this computation is already in-place.
562-
let result = tcx.dep_context().dep_graph().with_ignore(|| compute(*tcx.dep_context(), key));
563+
let result =
564+
tcx.dep_context().dep_graph().with_ignore(|| compute(*tcx.dep_context(), key.clone()));
563565

564566
prof_timer.finish_with_query_invocation_id(dep_node_index.into());
565567

0 commit comments

Comments
 (0)