From a9363dbe4e2cf0a10b9908d9bc1097c08937091f Mon Sep 17 00:00:00 2001 From: Egor Tiuvaev Date: Fri, 22 Mar 2024 15:19:44 +0100 Subject: [PATCH] Fix .gcda parsing for C++ templates --- src/parser.rs | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/src/parser.rs b/src/parser.rs index 761084577..34e4fd5f9 100644 --- a/src/parser.rs +++ b/src/parser.rs @@ -423,12 +423,17 @@ pub fn parse_gcov_gz(gcov_path: &Path) -> Result, Parse let mut lines = BTreeMap::new(); let mut branches = BTreeMap::new(); for mut line in file.lines.drain(..) { - lines.insert(line.line_number, line.count); + lines.entry(line.line_number) + .and_modify(|v|*v += line.count) + .or_insert(line.count); if !line.branches.is_empty() { - branches.insert( - line.line_number, - line.branches.drain(..).map(|b| b.count > 0).collect(), - ); + let values: Vec = line.branches.drain(..).map(|b| b.count > 0).collect(); + branches.entry(line.line_number) + .and_modify(|v: &mut Vec| + v.iter_mut().zip(values.iter()).for_each( + |(val, newval)|*val&=newval) + ) + .or_insert(values); } } if lines.is_empty() {