@@ -139,27 +139,13 @@ pub fn diff_data_section(
139139) -> Result < ( SectionDiff , SectionDiff ) > {
140140 let left_section = & left_obj. sections [ left_section_idx] ;
141141 let right_section = & right_obj. sections [ right_section_idx] ;
142- let left_max = left_obj
143- . symbols
144- . iter ( )
145- . filter_map ( |s| {
146- if s. section != Some ( left_section_idx) || s. kind == SymbolKind :: Section {
147- return None ;
148- }
149- s. address . checked_sub ( left_section. address ) . map ( |a| a + s. size )
150- } )
142+ let left_max = symbols_matching_section ( & left_obj. symbols , left_section_idx)
143+ . filter_map ( |( _, s) | s. address . checked_sub ( left_section. address ) . map ( |a| a + s. size ) )
151144 . max ( )
152145 . unwrap_or ( 0 )
153146 . min ( left_section. size ) ;
154- let right_max = right_obj
155- . symbols
156- . iter ( )
157- . filter_map ( |s| {
158- if s. section != Some ( right_section_idx) || s. kind == SymbolKind :: Section {
159- return None ;
160- }
161- s. address . checked_sub ( right_section. address ) . map ( |a| a + s. size )
162- } )
147+ let right_max = symbols_matching_section ( & right_obj. symbols , right_section_idx)
148+ . filter_map ( |( _, s) | s. address . checked_sub ( right_section. address ) . map ( |a| a + s. size ) )
163149 . max ( )
164150 . unwrap_or ( 0 )
165151 . min ( right_section. size ) ;
@@ -412,21 +398,13 @@ pub fn diff_generic_section(
412398 left_section_idx : usize ,
413399 _right_section_idx : usize ,
414400) -> Result < ( SectionDiff , SectionDiff ) > {
415- let match_percent = if left_obj
416- . symbols
417- . iter ( )
418- . enumerate ( )
419- . filter ( |( _, s) | s. section == Some ( left_section_idx) && s. kind != SymbolKind :: Section )
401+ let match_percent = if symbols_matching_section ( & left_obj. symbols , left_section_idx)
420402 . map ( |( i, _) | & left_diff. symbols [ i] )
421403 . all ( |d| d. match_percent == Some ( 100.0 ) )
422404 {
423405 100.0 // Avoid fp precision issues
424406 } else {
425- let ( matched, total) = left_obj
426- . symbols
427- . iter ( )
428- . enumerate ( )
429- . filter ( |( _, s) | s. section == Some ( left_section_idx) && s. kind != SymbolKind :: Section )
407+ let ( matched, total) = symbols_matching_section ( & left_obj. symbols , left_section_idx)
430408 . map ( |( i, s) | ( s, & left_diff. symbols [ i] ) )
431409 . fold ( ( 0.0 , 0.0 ) , |( matched, total) , ( s, d) | {
432410 ( matched + d. match_percent . unwrap_or ( 0.0 ) * s. size as f32 , total + s. size as f32 )
@@ -449,19 +427,11 @@ pub fn diff_bss_section(
449427 right_section_idx : usize ,
450428) -> Result < ( SectionDiff , SectionDiff ) > {
451429 let left_section = & left_obj. sections [ left_section_idx] ;
452- let left_sizes = left_obj
453- . symbols
454- . iter ( )
455- . enumerate ( )
456- . filter ( |( _, s) | s. section == Some ( left_section_idx) && s. kind != SymbolKind :: Section )
430+ let left_sizes = symbols_matching_section ( & left_obj. symbols , left_section_idx)
457431 . filter_map ( |( _, s) | s. address . checked_sub ( left_section. address ) . map ( |a| ( a, s. size ) ) )
458432 . collect :: < Vec < _ > > ( ) ;
459433 let right_section = & right_obj. sections [ right_section_idx] ;
460- let right_sizes = right_obj
461- . symbols
462- . iter ( )
463- . enumerate ( )
464- . filter ( |( _, s) | s. section == Some ( right_section_idx) && s. kind != SymbolKind :: Section )
434+ let right_sizes = symbols_matching_section ( & right_obj. symbols , right_section_idx)
465435 . filter_map ( |( _, s) | s. address . checked_sub ( right_section. address ) . map ( |a| ( a, s. size ) ) )
466436 . collect :: < Vec < _ > > ( ) ;
467437 let ops = capture_diff_slices ( Algorithm :: Patience , & left_sizes, & right_sizes) ;
@@ -487,3 +457,15 @@ pub fn diff_bss_section(
487457 SectionDiff { match_percent : Some ( match_percent) , data_diff : vec ! [ ] , reloc_diff : vec ! [ ] } ,
488458 ) )
489459}
460+
461+ fn symbols_matching_section (
462+ symbols : & [ Symbol ] ,
463+ section_idx : usize ,
464+ ) -> impl Iterator < Item = ( usize , & Symbol ) > + ' _ {
465+ symbols. iter ( ) . enumerate ( ) . filter ( move |( _, s) | {
466+ s. section == Some ( section_idx)
467+ && s. kind != SymbolKind :: Section
468+ && s. size > 0
469+ && !s. flags . contains ( SymbolFlag :: Ignored )
470+ } )
471+ }
0 commit comments