Skip to content
This repository was archived by the owner on May 28, 2025. It is now read-only.

Commit 1f71f0f

Browse files
committed
rustc_codegen_llvm: use IndexSet in CoverageMapGenerator
1 parent 997a766 commit 1f71f0f

File tree

2 files changed

+10
-16
lines changed

2 files changed

+10
-16
lines changed

src/librustc_codegen_llvm/coverageinfo/mapgen.rs

Lines changed: 5 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ use llvm::coverageinfo::CounterMappingRegion;
66
use log::debug;
77
use rustc_codegen_ssa::coverageinfo::map::{Counter, CounterExpression, Region};
88
use rustc_codegen_ssa::traits::{BaseTypeMethods, ConstMethods};
9-
use rustc_data_structures::fx::FxHashMap;
9+
use rustc_data_structures::fx::FxIndexSet;
1010
use rustc_llvm::RustString;
1111

1212
use std::ffi::CString;
@@ -76,13 +76,12 @@ pub fn finalize<'ll, 'tcx>(cx: &CodegenCx<'ll, 'tcx>) {
7676
}
7777

7878
struct CoverageMapGenerator {
79-
filenames: Vec<CString>,
80-
filename_to_index: FxHashMap<CString, u32>,
79+
filenames: FxIndexSet<CString>,
8180
}
8281

8382
impl CoverageMapGenerator {
8483
fn new() -> Self {
85-
Self { filenames: Vec::new(), filename_to_index: FxHashMap::default() }
84+
Self { filenames: FxIndexSet::default() }
8685
}
8786

8887
/// Using the `expressions` and `counter_regions` collected for the current function, generate
@@ -122,16 +121,8 @@ impl CoverageMapGenerator {
122121
let c_filename =
123122
CString::new(file_name).expect("null error converting filename to C string");
124123
debug!(" file_id: {} = '{:?}'", current_file_id, c_filename);
125-
let filenames_index = match self.filename_to_index.get(&c_filename) {
126-
Some(index) => *index,
127-
None => {
128-
let index = self.filenames.len() as u32;
129-
self.filenames.push(c_filename.clone());
130-
self.filename_to_index.insert(c_filename.clone(), index);
131-
index
132-
}
133-
};
134-
virtual_file_mapping.push(filenames_index);
124+
let (filenames_index, _) = self.filenames.insert_full(c_filename);
125+
virtual_file_mapping.push(filenames_index as u32);
135126
}
136127
mapping_regions.push(CounterMappingRegion::code_region(
137128
counter,

src/librustc_codegen_llvm/coverageinfo/mod.rs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -97,8 +97,11 @@ impl CoverageInfoBuilderMethods<'tcx> for Builder<'a, 'll, 'tcx> {
9797
}
9898
}
9999

100-
pub(crate) fn write_filenames_section_to_buffer(filenames: &Vec<CString>, buffer: &RustString) {
101-
let c_str_vec = filenames.iter().map(|cstring| cstring.as_ptr()).collect::<Vec<_>>();
100+
pub(crate) fn write_filenames_section_to_buffer<'a>(
101+
filenames: impl IntoIterator<Item = &'a CString>,
102+
buffer: &RustString,
103+
) {
104+
let c_str_vec = filenames.into_iter().map(|cstring| cstring.as_ptr()).collect::<Vec<_>>();
102105
unsafe {
103106
llvm::LLVMRustCoverageWriteFilenamesSectionToBuffer(
104107
c_str_vec.as_ptr(),

0 commit comments

Comments
 (0)