Skip to content

Commit b8895e9

Browse files
committed
Create dummy_{source,sink} lazily.
Because they're rarely needed. This gives a very small but very easy perf win.
1 parent c609da5 commit b8895e9

File tree

1 file changed

+8
-4
lines changed
  • compiler/rustc_infer/src/infer/lexical_region_resolve

1 file changed

+8
-4
lines changed

compiler/rustc_infer/src/infer/lexical_region_resolve/mod.rs

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -692,8 +692,10 @@ impl<'cx, 'tcx> LexicalResolver<'cx, 'tcx> {
692692
// (dummy_sink). In `dummy -> a -> b -> dummy`, using one
693693
// dummy node leads one to think (erroneously) there exists a
694694
// path from `b` to `a`. Two dummy nodes sidesteps the issue.
695-
let dummy_source = graph.add_node(());
696-
let dummy_sink = graph.add_node(());
695+
// Construct them lazily because they're rarely needed and this
696+
// code is hot enough for that to matter.
697+
let mut dummy_source = None;
698+
let mut dummy_sink = None;
697699

698700
for constraint in self.data.constraints.keys() {
699701
match *constraint {
@@ -705,10 +707,12 @@ impl<'cx, 'tcx> LexicalResolver<'cx, 'tcx> {
705707
);
706708
}
707709
Constraint::RegSubVar(_, b_id) => {
708-
graph.add_edge(dummy_source, NodeIndex(b_id.index() as usize), *constraint);
710+
let d = dummy_source.get_or_insert_with(|| graph.add_node(()));
711+
graph.add_edge(*d, NodeIndex(b_id.index() as usize), *constraint);
709712
}
710713
Constraint::VarSubReg(a_id, _) => {
711-
graph.add_edge(NodeIndex(a_id.index() as usize), dummy_sink, *constraint);
714+
let d = dummy_sink.get_or_insert_with(|| graph.add_node(()));
715+
graph.add_edge(NodeIndex(a_id.index() as usize), *d, *constraint);
712716
}
713717
Constraint::RegSubReg(..) => {
714718
// this would be an edge from `dummy_source` to

0 commit comments

Comments
 (0)