@@ -658,15 +658,19 @@ fn find_symbol(
658658
659659/// Find matching sections between each object.
660660fn 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+ ) ;
662666 if let Some ( left) = left {
663667 for ( section_idx, section) in left. sections . iter ( ) . enumerate ( ) {
664668 if section. kind == SectionKind :: Unknown {
665669 continue ;
666670 }
667671 matches. push ( SectionMatch {
668672 left : Some ( section_idx) ,
669- right : find_section ( right, & section. name , section. kind ) ,
673+ right : find_section ( right, & section. name , section. kind , & matches ) ,
670674 section_kind : section. kind ,
671675 } ) ;
672676 }
@@ -689,6 +693,13 @@ fn matching_sections(left: Option<&Object>, right: Option<&Object>) -> Result<Ve
689693 Ok ( matches)
690694}
691695
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+ } )
694705}
0 commit comments