@@ -692,8 +692,10 @@ impl<'cx, 'tcx> LexicalResolver<'cx, 'tcx> {
692
692
// (dummy_sink). In `dummy -> a -> b -> dummy`, using one
693
693
// dummy node leads one to think (erroneously) there exists a
694
694
// 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 ;
697
699
698
700
for constraint in self . data . constraints . keys ( ) {
699
701
match * constraint {
@@ -705,10 +707,12 @@ impl<'cx, 'tcx> LexicalResolver<'cx, 'tcx> {
705
707
) ;
706
708
}
707
709
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) ;
709
712
}
710
713
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) ;
712
716
}
713
717
Constraint :: RegSubReg ( ..) => {
714
718
// this would be an edge from `dummy_source` to
0 commit comments