Skip to content

Commit 3db0727

Browse files
committed
Omit match % for right sections, improve multi-section diffing
Fixes #120
1 parent 8b5bf21 commit 3db0727

File tree

3 files changed

+18
-10
lines changed

3 files changed

+18
-10
lines changed

objdiff-core/src/diff/data.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -274,7 +274,6 @@ pub fn diff_data_section(
274274
// We only do this when all relocations on the left side match.
275275
if left_section_diff.match_percent.unwrap_or(-1.0) < match_percent {
276276
left_section_diff.match_percent = Some(match_percent);
277-
right_section_diff.match_percent = Some(match_percent);
278277
}
279278
}
280279
Ok((left_section_diff, right_section_diff))
@@ -413,7 +412,7 @@ pub fn diff_generic_section(
413412
};
414413
Ok((
415414
SectionDiff { match_percent: Some(match_percent), data_diff: vec![], reloc_diff: vec![] },
416-
SectionDiff { match_percent: Some(match_percent), data_diff: vec![], reloc_diff: vec![] },
415+
SectionDiff { match_percent: None, data_diff: vec![], reloc_diff: vec![] },
417416
))
418417
}
419418

@@ -454,7 +453,7 @@ pub fn diff_bss_section(
454453

455454
Ok((
456455
SectionDiff { match_percent: Some(match_percent), data_diff: vec![], reloc_diff: vec![] },
457-
SectionDiff { match_percent: Some(match_percent), data_diff: vec![], reloc_diff: vec![] },
456+
SectionDiff { match_percent: None, data_diff: vec![], reloc_diff: vec![] },
458457
))
459458
}
460459

objdiff-core/src/diff/display.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -600,9 +600,7 @@ fn symbol_matches_filter(
600600
return false;
601601
}
602602
if !show_hidden_symbols
603-
&& (symbol.size == 0
604-
|| symbol.flags.contains(SymbolFlag::Hidden)
605-
|| symbol.flags.contains(SymbolFlag::Ignored))
603+
&& (symbol.size == 0 || symbol.flags.contains(SymbolFlag::Hidden | SymbolFlag::Ignored))
606604
{
607605
return false;
608606
}

objdiff-core/src/diff/mod.rs

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -658,15 +658,19 @@ fn find_symbol(
658658

659659
/// Find matching sections between each object.
660660
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+
);
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

Comments
 (0)