@@ -468,75 +468,17 @@ struct ChangeCounter {
468468 pub use_it : bool ,
469469}
470470
471- impl SortedBuildIterator {
472- pub async fn new (
473- _options : OptionMap ,
474- source : Arc < tokio:: sync:: Mutex < dyn BuildIterator + Send > > ,
475- builds_with_impossible_requests : HashMap < BuildIdent , Compatibility > ,
476- ) -> Result < Self > {
477- // Note: _options is unused in this implementation, it was used
478- // in the by_distance sorting implementation
479- let mut builds = VecDeque :: < BuildWithRepos > :: new ( ) ;
480- {
481- let mut source_lock = source. lock ( ) . await ;
482- while let Some ( item) = source_lock. next ( ) . await ? {
483- builds. push_back ( item) ;
484- }
485- }
486-
487- let mut sbi = SortedBuildIterator { builds } ;
488-
489- sbi. sort_by_build_option_values ( builds_with_impossible_requests)
490- . await ;
491- Ok ( sbi)
492- }
493-
494- pub async fn new_from_builds (
495- builds : VecDeque < BuildWithRepos > ,
496- builds_with_impossible_requests : HashMap < BuildIdent , Compatibility > ,
497- ) -> Result < Self > {
498- let mut sbi = SortedBuildIterator { builds } ;
499-
500- sbi. sort_by_build_option_values ( builds_with_impossible_requests)
501- . await ;
502- Ok ( sbi)
503- }
504-
505- /// Helper for making BuildKey structures used in the sorting in
506- /// sort_by_build_option_values() below
507- fn make_option_values_build_key (
508- spec : & Spec ,
509- ordered_names : & Vec < OptNameBuf > ,
510- build_name_values : & HashMap < BuildIdent , OptionMap > ,
511- makes_an_impossible_request : bool ,
512- ) -> BuildKey {
513- let build_id = spec. ident ( ) ;
514- let empty = OptionMap :: default ( ) ;
515- let name_values = match build_name_values. get ( build_id) {
516- Some ( nv) => nv,
517- None => & empty,
518- } ;
519- BuildKey :: new (
520- spec. ident ( ) ,
521- ordered_names,
522- name_values,
523- makes_an_impossible_request,
524- )
525- }
526-
527- /// Sorts builds by keys based on ordered build option names and
528- /// differing values in those options
529- async fn sort_by_build_option_values (
530- & mut self ,
531- builds_with_impossible_requests : HashMap < BuildIdent , Compatibility > ,
532- ) {
533- let start = Instant :: now ( ) ;
471+ pub struct BuildToSortedOptName { }
534472
473+ impl BuildToSortedOptName {
474+ pub fn sort_builds < ' a > (
475+ builds : impl Iterator < Item = & ' a ( Arc < Spec > , PackageSource ) > ,
476+ ) -> ( Vec < OptNameBuf > , HashMap < BuildIdent , OptionMap > ) {
535477 let mut number_non_src_builds: u64 = 0 ;
536478 let mut build_name_values: HashMap < BuildIdent , OptionMap > = HashMap :: default ( ) ;
537479 let mut changes: HashMap < OptNameBuf , ChangeCounter > = HashMap :: new ( ) ;
538480
539- for ( build, _) in self . builds . iter ( ) . flat_map ( |hm| hm . values ( ) ) {
481+ for ( build, _) in builds {
540482 // Skip this if it's a '/src' build because '/src' builds
541483 // won't use the build option values in their key, they
542484 // don't need to be looked at. They have a type of key
@@ -622,6 +564,77 @@ impl SortedBuildIterator {
622564 // position for a site's spk setup.
623565 BUILD_KEY_NAME_ORDER . promote_names ( key_entry_names. as_mut_slice ( ) , |n| n) ;
624566
567+ ( key_entry_names, build_name_values)
568+ }
569+ }
570+
571+ impl SortedBuildIterator {
572+ pub async fn new (
573+ _options : OptionMap ,
574+ source : Arc < tokio:: sync:: Mutex < dyn BuildIterator + Send > > ,
575+ builds_with_impossible_requests : HashMap < BuildIdent , Compatibility > ,
576+ ) -> Result < Self > {
577+ // Note: _options is unused in this implementation, it was used
578+ // in the by_distance sorting implementation
579+ let mut builds = VecDeque :: < BuildWithRepos > :: new ( ) ;
580+ {
581+ let mut source_lock = source. lock ( ) . await ;
582+ while let Some ( item) = source_lock. next ( ) . await ? {
583+ builds. push_back ( item) ;
584+ }
585+ }
586+
587+ let mut sbi = SortedBuildIterator { builds } ;
588+
589+ sbi. sort_by_build_option_values ( builds_with_impossible_requests)
590+ . await ;
591+ Ok ( sbi)
592+ }
593+
594+ pub async fn new_from_builds (
595+ builds : VecDeque < BuildWithRepos > ,
596+ builds_with_impossible_requests : HashMap < BuildIdent , Compatibility > ,
597+ ) -> Result < Self > {
598+ let mut sbi = SortedBuildIterator { builds } ;
599+
600+ sbi. sort_by_build_option_values ( builds_with_impossible_requests)
601+ . await ;
602+ Ok ( sbi)
603+ }
604+
605+ /// Helper for making BuildKey structures used in the sorting in
606+ /// sort_by_build_option_values() below
607+ fn make_option_values_build_key (
608+ spec : & Spec ,
609+ ordered_names : & Vec < OptNameBuf > ,
610+ build_name_values : & HashMap < BuildIdent , OptionMap > ,
611+ makes_an_impossible_request : bool ,
612+ ) -> BuildKey {
613+ let build_id = spec. ident ( ) ;
614+ let empty = OptionMap :: default ( ) ;
615+ let name_values = match build_name_values. get ( build_id) {
616+ Some ( nv) => nv,
617+ None => & empty,
618+ } ;
619+ BuildKey :: new (
620+ spec. ident ( ) ,
621+ ordered_names,
622+ name_values,
623+ makes_an_impossible_request,
624+ )
625+ }
626+
627+ /// Sorts builds by keys based on ordered build option names and
628+ /// differing values in those options
629+ async fn sort_by_build_option_values (
630+ & mut self ,
631+ builds_with_impossible_requests : HashMap < BuildIdent , Compatibility > ,
632+ ) {
633+ let start = Instant :: now ( ) ;
634+
635+ let ( key_entry_names, build_name_values) =
636+ BuildToSortedOptName :: sort_builds ( self . builds . iter ( ) . flat_map ( |hm| hm. values ( ) ) ) ;
637+
625638 // Sort the builds by their generated keys generated from the
626639 // ordered names and values worth including.
627640 self . builds . make_contiguous ( ) . sort_by_cached_key ( |hm| {
0 commit comments