File tree Expand file tree Collapse file tree 1 file changed +19
-8
lines changed Expand file tree Collapse file tree 1 file changed +19
-8
lines changed Original file line number Diff line number Diff line change @@ -114,15 +114,8 @@ impl Scheduler {
114114 ( scheduler, queues)
115115 }
116116
117- #[ inline]
118117 fn least_loaded_worker ( & self ) -> & Worker {
119- unsafe {
120- self . workers
121- . next_batch ( )
122- . iter ( )
123- . min_by_key ( |a| a. len . get ( ) )
124- . unwrap_unchecked ( )
125- }
118+ unsafe { min_by_key ( self . workers . next_batch ( ) , |w| w. len . get ( ) ) }
126119 }
127120
128121 pub fn schedule ( & self , task : Task ) {
@@ -165,3 +158,21 @@ impl Clone for Scheduler {
165158 }
166159 }
167160}
161+
162+ #[ inline]
163+ unsafe fn min_by_key < T , B : Ord > ( data : & [ T ] , f : fn ( & T ) -> B ) -> & T {
164+ debug_assert ! ( !data. is_empty( ) ) ;
165+
166+ let mut val_x = data. get_unchecked ( 0 ) ;
167+ let mut x = f ( val_x) ;
168+
169+ for val_y in data. get_unchecked ( 1 ..) {
170+ let y = f ( val_y) ;
171+ if x < y {
172+ break ;
173+ }
174+ x = y;
175+ val_x = val_y;
176+ }
177+ val_x
178+ }
You can’t perform that action at this time.
0 commit comments