Skip to content

Commit 384d04d

Browse files
committed
Reduce the number of clone()s needed in obligation_forest
Some can be avoided by using remove_entry instead of remove.
1 parent d334027 commit 384d04d

File tree

1 file changed

+8
-3
lines changed
  • src/librustc_data_structures/obligation_forest

1 file changed

+8
-3
lines changed

src/librustc_data_structures/obligation_forest/mod.rs

+8-3
Original file line numberDiff line numberDiff line change
@@ -496,9 +496,14 @@ impl<O: ForestObligation> ObligationForest<O> {
496496
}
497497
}
498498
NodeState::Done => {
499-
self.waiting_cache.remove(self.nodes[i].obligation.as_predicate());
500-
// FIXME(HashMap): why can't I get my key back?
501-
self.done_cache.insert(self.nodes[i].obligation.as_predicate().clone());
499+
// Avoid cloning the key (predicate) in case it exists in the waiting cache
500+
if let Some((predicate, _)) = self.waiting_cache
501+
.remove_entry(self.nodes[i].obligation.as_predicate())
502+
{
503+
self.done_cache.insert(predicate);
504+
} else {
505+
self.done_cache.insert(self.nodes[i].obligation.as_predicate().clone());
506+
}
502507
node_rewrites[i] = nodes_len;
503508
dead_nodes += 1;
504509
}

0 commit comments

Comments
 (0)