File tree Expand file tree Collapse file tree
compiler/rustc_data_structures/src/sync Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -129,12 +129,28 @@ fn par_slice<I: DynSend>(
129129 for_each : impl Fn ( & mut I ) + DynSync + DynSend ,
130130 proof : FromDyn < ( ) > ,
131131) {
132+ match items {
133+ [ ] => return ,
134+ [ item] => {
135+ guard. run ( || for_each ( item) ) ;
136+ return ;
137+ }
138+ _ => ( ) ,
139+ }
140+
132141 let for_each = proof. derive ( for_each) ;
133142 let mut items = for_each. derive ( items) ;
134143 rustc_thread_pool:: scope ( |s| {
135144 let proof = items. derive ( ( ) ) ;
136- let group_size = std:: cmp:: max ( items. len ( ) / 128 , 1 ) ;
137- for group in items. chunks_mut ( group_size) {
145+
146+ const MAX_GROUP_COUNT : usize = 128 ;
147+ let group_size = items. len ( ) . div_ceil ( MAX_GROUP_COUNT ) ;
148+ let groups = items. chunks_mut ( group_size) ;
149+
150+ // Reverse the order of the later functions since Rayon executes them in reverse
151+ // order when using a single thread. This ensures the execution order matches
152+ // that of a single threaded rustc.
153+ for group in groups. rev ( ) {
138154 let group = proof. derive ( group) ;
139155 s. spawn ( |_| {
140156 let mut group = group;
You can’t perform that action at this time.
0 commit comments