@@ -19,8 +19,8 @@ use rustc_data_structures::fx::FxHashSet;
1919use rustc_data_structures:: graph:: implementation:: {
2020 Direction , Graph , NodeIndex , INCOMING , OUTGOING ,
2121} ;
22+ use rustc_index:: bit_set:: BitSet ;
2223use rustc_index:: vec:: { Idx , IndexVec } ;
23- use smallvec:: SmallVec ;
2424use std:: fmt;
2525use syntax_pos:: Span ;
2626
@@ -870,21 +870,34 @@ impl<'cx, 'tcx> LexicalResolver<'cx, 'tcx> {
870870 where
871871 F : FnMut ( & Constraint < ' tcx > ) -> ( bool , bool ) ,
872872 {
873- let mut constraints: SmallVec < [ _ ; 16 ] > = self . data . constraints . keys ( ) . collect ( ) ;
873+ // Using bitsets to track the remaining elements is faster than using a
874+ // `Vec` by itself (which requires removing elements, which requires
875+ // element shuffling, which is slow).
876+ let constraints: Vec < _ > = self . data . constraints . keys ( ) . collect ( ) ;
877+ let mut live_indices: BitSet < usize > = BitSet :: new_filled ( constraints. len ( ) ) ;
878+ let mut killed_indices: BitSet < usize > = BitSet :: new_empty ( constraints. len ( ) ) ;
874879 let mut iteration = 0 ;
875880 let mut changed = true ;
876881 while changed {
877882 changed = false ;
878883 iteration += 1 ;
879884 debug ! ( "---- Expansion iteration {}" , iteration) ;
880- constraints. retain ( |constraint| {
885+ for index in live_indices. iter ( ) {
886+ let constraint = constraints[ index] ;
881887 let ( edge_changed, retain) = body ( constraint) ;
882888 if edge_changed {
883889 debug ! ( "updated due to constraint {:?}" , constraint) ;
884890 changed = true ;
885891 }
886- retain
887- } ) ;
892+ if !retain {
893+ let changed = killed_indices. insert ( index) ;
894+ debug_assert ! ( changed) ;
895+ }
896+ }
897+ live_indices. subtract ( & killed_indices) ;
898+
899+ // We could clear `killed_indices` here, but we don't need to and
900+ // it's cheaper not to.
888901 }
889902 debug ! ( "---- Expansion complete after {} iteration(s)" , iteration) ;
890903 }
0 commit comments