Skip to content
This repository was archived by the owner on Nov 1, 2023. It is now read-only.

Commit 68a3fe2

Browse files
committed
Add a case insensitive transformer for better perf
1 parent 874bbb0 commit 68a3fe2

File tree

1 file changed

+29
-8
lines changed

1 file changed

+29
-8
lines changed

src/agent/coverage/src/source.rs

Lines changed: 29 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
// Licensed under the MIT License.
33

44
use std::collections::{BTreeMap, BTreeSet};
5+
use std::convert;
56
use std::num::NonZeroU32;
67

78
use anyhow::{Context, Result};
@@ -11,6 +12,7 @@ use debuggable_module::load_module::LoadModule;
1112
use debuggable_module::loader::Loader;
1213
use debuggable_module::path::FilePath;
1314
use debuggable_module::{Module, Offset};
15+
use symbolic::symcache::transform::{SourceLocation, Transformer};
1416

1517
use crate::allowlist::AllowList;
1618
use crate::binary::BinaryCoverage;
@@ -69,6 +71,30 @@ pub fn binary_to_source_coverage(
6971
let mut symcache = vec![];
7072
let mut converter = SymCacheConverter::new();
7173

74+
if cfg!(windows) {
75+
use symbolic::symcache::transform::Function;
76+
struct CaseInsensitive {}
77+
impl Transformer for CaseInsensitive {
78+
fn transform_function<'f>(&'f mut self, f: Function<'f>) -> Function<'f> {
79+
f
80+
}
81+
82+
fn transform_source_location<'f>(
83+
&'f mut self,
84+
mut sl: SourceLocation<'f>,
85+
) -> SourceLocation<'f> {
86+
sl.file.name = sl.file.name.to_ascii_lowercase().into();
87+
sl.file.directory = sl.file.directory.map(|d| d.to_ascii_lowercase().into());
88+
sl.file.comp_dir = sl.file.comp_dir.map(|d| d.to_ascii_lowercase().into());
89+
sl
90+
}
91+
}
92+
93+
let case_insensitive_transformer = CaseInsensitive {};
94+
95+
converter.add_transformer(case_insensitive_transformer);
96+
}
97+
7298
let exe = Object::parse(module.executable_data())?;
7399
converter.process_object(&exe)?;
74100

@@ -104,18 +130,13 @@ pub fn binary_to_source_coverage(
104130
};
105131

106132
if let Some(file) = location.file() {
107-
let file_path = if cfg!(windows) {
108-
// Windows paths are case insensitive.
109-
FilePath::new(file.full_path().to_ascii_lowercase())?
110-
} else {
111-
FilePath::new(file.full_path())?
112-
};
113-
114133
// Only include relevant inlinees.
115-
if !source_allowlist.is_allowed(&file_path) {
134+
if !source_allowlist.is_allowed(&file.full_path()) {
116135
continue;
117136
}
118137

138+
let file_path = FilePath::new(file.full_path())?;
139+
119140
// We have a hit.
120141
let file_coverage = source.files.entry(file_path).or_default();
121142
let line = Line(line_number);

0 commit comments

Comments
 (0)