MCPcopy Index your code
hub / github.com/encounter/objdiff / apply_symbol_mappings

Function apply_symbol_mappings

objdiff-core/src/diff/mod.rs:509–572  ·  view source on GitHub ↗
(
    left: &Object,
    right: &Object,
    mapping_config: &MappingConfig,
    left_used: &mut BTreeSet<usize>,
    right_used: &mut BTreeSet<usize>,
    matches: &mut Vec<SymbolMatch>,
)

Source from the content-addressed store, hash-verified

507}
508
509fn apply_symbol_mappings(
510 left: &Object,
511 right: &Object,
512 mapping_config: &MappingConfig,
513 left_used: &mut BTreeSet<usize>,
514 right_used: &mut BTreeSet<usize>,
515 matches: &mut Vec<SymbolMatch>,
516) -> Result<()> {
517 // If we're selecting a symbol to use as a comparison, mark it as used
518 // This ensures that we don't match it to another symbol at any point
519 if let Some(left_name) = &mapping_config.selecting_left
520 && let Some(left_symbol) = left.symbol_by_name(left_name)
521 {
522 left_used.insert(left_symbol);
523 }
524 if let Some(right_name) = &mapping_config.selecting_right
525 && let Some(right_symbol) = right.symbol_by_name(right_name)
526 {
527 right_used.insert(right_symbol);
528 }
529
530 // Apply manual symbol mappings
531 for (left_name, right_name) in &mapping_config.mappings {
532 let Some(left_symbol_index) = left.symbol_by_name(left_name) else {
533 continue;
534 };
535 if left_used.contains(&left_symbol_index) {
536 continue;
537 }
538 let Some(right_symbol_index) = right.symbol_by_name(right_name) else {
539 continue;
540 };
541 if right_used.contains(&right_symbol_index) {
542 continue;
543 }
544 let left_section_kind = left
545 .symbols
546 .get(left_symbol_index)
547 .and_then(|s| s.section)
548 .and_then(|section_index| left.sections.get(section_index))
549 .map_or(SectionKind::Unknown, |s| s.kind);
550 let right_section_kind = right
551 .symbols
552 .get(right_symbol_index)
553 .and_then(|s| s.section)
554 .and_then(|section_index| right.sections.get(section_index))
555 .map_or(SectionKind::Unknown, |s| s.kind);
556 if left_section_kind != right_section_kind {
557 log::warn!(
558 "Symbol section kind mismatch: {left_name} ({left_section_kind:?}) vs {right_name} ({right_section_kind:?})"
559 );
560 continue;
561 }
562 matches.push(SymbolMatch {
563 left: Some(left_symbol_index),
564 right: Some(right_symbol_index),
565 prev: None, // TODO
566 section_kind: left_section_kind,

Callers 1

matching_symbolsFunction · 0.85

Calls 3

symbol_by_nameMethod · 0.80
getMethod · 0.80
pushMethod · 0.80

Tested by

no test coverage detected