Skip to content

Commit 8cd8b23

Browse files
committed
coverage: Hoist counter_for_bcb out of its loop
Having this helper function in the loop was confusing, because it doesn't rely on anything that changes between loop iterations.
1 parent 339556e commit 8cd8b23

File tree

1 file changed

+10
-10
lines changed
  • compiler/rustc_codegen_llvm/src/coverageinfo/mapgen

1 file changed

+10
-10
lines changed

compiler/rustc_codegen_llvm/src/coverageinfo/mapgen/covfun.rs

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,16 @@ fn fill_region_tables<'tcx>(
104104
ids_info: &'tcx CoverageIdsInfo,
105105
covfun: &mut CovfunRecord<'tcx>,
106106
) {
107+
// If this function is unused, replace all counters with zero.
108+
let counter_for_bcb = |bcb: BasicCoverageBlock| -> ffi::Counter {
109+
let term = if covfun.is_used {
110+
ids_info.term_for_bcb[bcb].expect("every BCB in a mapping was given a term")
111+
} else {
112+
CovTerm::Zero
113+
};
114+
ffi::Counter::from_term(term)
115+
};
116+
107117
// Currently a function's mappings must all be in the same file, so use the
108118
// first mapping's span to determine the file.
109119
let source_map = tcx.sess.source_map();
@@ -135,16 +145,6 @@ fn fill_region_tables<'tcx>(
135145
// For each counter/region pair in this function+file, convert it to a
136146
// form suitable for FFI.
137147
for &Mapping { ref kind, span } in &fn_cov_info.mappings {
138-
// If this function is unused, replace all counters with zero.
139-
let counter_for_bcb = |bcb: BasicCoverageBlock| -> ffi::Counter {
140-
let term = if covfun.is_used {
141-
ids_info.term_for_bcb[bcb].expect("every BCB in a mapping was given a term")
142-
} else {
143-
CovTerm::Zero
144-
};
145-
ffi::Counter::from_term(term)
146-
};
147-
148148
let Some(coords) = make_coords(span) else { continue };
149149
let cov_span = coords.make_coverage_span(local_file_id);
150150

0 commit comments

Comments
 (0)