@@ -658,15 +658,19 @@ fn find_symbol(
658
658
659
659
/// Find matching sections between each object.
660
660
fn matching_sections ( left : Option < & Object > , right : Option < & Object > ) -> Result < Vec < SectionMatch > > {
661
- let mut matches = Vec :: new ( ) ;
661
+ let mut matches = Vec :: with_capacity (
662
+ left. as_ref ( )
663
+ . map_or ( 0 , |o| o. sections . len ( ) )
664
+ . max ( right. as_ref ( ) . map_or ( 0 , |o| o. sections . len ( ) ) ) ,
665
+ ) ;
662
666
if let Some ( left) = left {
663
667
for ( section_idx, section) in left. sections . iter ( ) . enumerate ( ) {
664
668
if section. kind == SectionKind :: Unknown {
665
669
continue ;
666
670
}
667
671
matches. push ( SectionMatch {
668
672
left : Some ( section_idx) ,
669
- right : find_section ( right, & section. name , section. kind ) ,
673
+ right : find_section ( right, & section. name , section. kind , & matches ) ,
670
674
section_kind : section. kind ,
671
675
} ) ;
672
676
}
@@ -689,6 +693,13 @@ fn matching_sections(left: Option<&Object>, right: Option<&Object>) -> Result<Ve
689
693
Ok ( matches)
690
694
}
691
695
692
- fn find_section ( obj : Option < & Object > , name : & str , section_kind : SectionKind ) -> Option < usize > {
693
- obj?. sections . iter ( ) . position ( |s| s. kind == section_kind && s. name == name)
696
+ fn find_section (
697
+ obj : Option < & Object > ,
698
+ name : & str ,
699
+ section_kind : SectionKind ,
700
+ matches : & [ SectionMatch ] ,
701
+ ) -> Option < usize > {
702
+ obj?. sections . iter ( ) . enumerate ( ) . position ( |( i, s) | {
703
+ s. kind == section_kind && s. name == name && !matches. iter ( ) . any ( |m| m. right == Some ( i) )
704
+ } )
694
705
}
0 commit comments