From 6816315fac3f1d2bf36e00f5f93b326872a5b08e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20M=C3=BCller?= Date: Mon, 18 Sep 2023 13:29:06 -0700 Subject: [PATCH] Remove code duplication in Symbolizer::symbolize_with_resolver() MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 --- src/symbolize/symbolizer.rs | 55 ++++++++++++------------------------- 1 file changed, 18 insertions(+), 37 deletions(-) diff --git a/src/symbolize/symbolizer.rs b/src/symbolize/symbolizer.rs index 1fd30bce..96501060 100644 --- a/src/symbolize/symbolizer.rs +++ b/src/symbolize/symbolizer.rs @@ -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) }