Skip to content

Commit 16843ce

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 33706fc commit 16843ce

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
@@ -106,6 +106,16 @@ fn fill_region_tables<'tcx>(
106106
ids_info: &'tcx CoverageIdsInfo,
107107
covfun: &mut CovfunRecord<'tcx>,
108108
) {
109+
// If this function is unused, replace all counters with zero.
110+
let counter_for_bcb = |bcb: BasicCoverageBlock| -> ffi::Counter {
111+
let term = if covfun.is_used {
112+
ids_info.term_for_bcb[bcb].expect("every BCB in a mapping was given a term")
113+
} else {
114+
CovTerm::Zero
115+
};
116+
ffi::Counter::from_term(term)
117+
};
118+
109119
// Currently a function's mappings must all be in the same file, so use the
110120
// first mapping's span to determine the file.
111121
let source_map = tcx.sess.source_map();
@@ -137,16 +147,6 @@ fn fill_region_tables<'tcx>(
137147
// For each counter/region pair in this function+file, convert it to a
138148
// form suitable for FFI.
139149
for &Mapping { ref kind, span } in &fn_cov_info.mappings {
140-
// If this function is unused, replace all counters with zero.
141-
let counter_for_bcb = |bcb: BasicCoverageBlock| -> ffi::Counter {
142-
let term = if covfun.is_used {
143-
ids_info.term_for_bcb[bcb].expect("every BCB in a mapping was given a term")
144-
} else {
145-
CovTerm::Zero
146-
};
147-
ffi::Counter::from_term(term)
148-
};
149-
150150
let Some(coords) = make_coords(span) else { continue };
151151
let cov_span = coords.make_coverage_span(local_file_id);
152152

0 commit comments

Comments
 (0)