Skip to content

Commit

Permalink
Remove code duplication in Symbolizer::symbolize_with_resolver()
Browse files Browse the repository at this point in the history
This change removes some annoying code duplication in
Symbolizer::symbolize_with_resolver(), that repeatedly turned out to be
a maintenance complication.

Signed-off-by: Daniel Müller <[email protected]>
  • Loading branch information
d-e-s-o committed Sep 18, 2023
1 parent 45ac4c4 commit 6816315
Showing 1 changed file with 18 additions and 37 deletions.
55 changes: 18 additions & 37 deletions src/symbolize/symbolizer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -250,43 +250,24 @@ impl Symbolizer {

let mut results = vec![];
for sym in syms {
if let Some(ref linfo) = linfo {
let IntSym {
name,
addr: sym_addr,
size: sym_size,
lang,
} = sym;
results.push(Sym {
name: self.maybe_demangle(name, lang),
addr: sym_addr,
offset: addr - sym_addr,
size: sym_size,
dir: Some(linfo.dir.to_path_buf()),
file: Some(linfo.file.to_os_string()),
line: linfo.line,
column: linfo.column,
_non_exhaustive: (),
});
} else {
let IntSym {
name,
addr: sym_addr,
size: sym_size,
lang,
} = sym;
results.push(Sym {
name: self.maybe_demangle(name, lang),
addr: sym_addr,
offset: addr - sym_addr,
size: sym_size,
dir: None,
file: None,
line: None,
column: None,
_non_exhaustive: (),
});
}
let IntSym {
name,
addr: sym_addr,
size: sym_size,
lang,
} = sym;

results.push(Sym {
name: self.maybe_demangle(name, lang),
addr: sym_addr,
offset: addr - sym_addr,
size: sym_size,
dir: linfo.as_ref().map(|linfo| linfo.dir.to_path_buf()),
file: linfo.as_ref().map(|linfo| linfo.file.to_os_string()),
line: linfo.as_ref().and_then(|linfo| linfo.line),
column: linfo.as_ref().and_then(|linfo| linfo.column),
_non_exhaustive: (),
});
}
Ok(results)
}
Expand Down

0 comments on commit 6816315

Please sign in to comment.