Skip to content

Commit

Permalink
coverage: Push down the call to get_expressions_and_counter_regions
Browse files Browse the repository at this point in the history
These expressions and counter regions are only needed by the function that
encodes a function's coverage mappings payload.
  • Loading branch information
Zalathar committed Sep 9, 2023
1 parent 57b3d03 commit a7bdfd4
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions compiler/rustc_codegen_llvm/src/coverageinfo/mapgen.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use crate::common::CodegenCx;
use crate::coverageinfo;
use crate::coverageinfo::ffi::{Counter, CounterExpression, CounterMappingRegion};
use crate::coverageinfo::ffi::CounterMappingRegion;
use crate::coverageinfo::map_data::FunctionCoverage;
use crate::llvm;

use rustc_codegen_ssa::traits::ConstMethods;
Expand Down Expand Up @@ -63,11 +64,9 @@ pub fn finalize(cx: &CodegenCx<'_, '_>) {
let mangled_function_name = tcx.symbol_name(instance).name;
let source_hash = function_coverage.source_hash();
let is_used = function_coverage.is_used();
let (expressions, counter_regions) =
function_coverage.get_expressions_and_counter_regions();

let coverage_mapping_buffer =
encode_mappings_for_function(&mut global_file_table, expressions, counter_regions);
encode_mappings_for_function(&mut global_file_table, &function_coverage);

if coverage_mapping_buffer.is_empty() {
if function_coverage.is_used() {
Expand Down Expand Up @@ -153,11 +152,12 @@ impl GlobalFileTable {
/// entry. The payload is returned as a vector of bytes.
///
/// Newly-encountered filenames will be added to the global file table.
fn encode_mappings_for_function<'a>(
fn encode_mappings_for_function(
global_file_table: &mut GlobalFileTable,
expressions: Vec<CounterExpression>,
counter_regions: impl Iterator<Item = (Counter, &'a CodeRegion)>,
function_coverage: &FunctionCoverage<'_>,
) -> Vec<u8> {
let (expressions, counter_regions) = function_coverage.get_expressions_and_counter_regions();

let mut counter_regions = counter_regions.collect::<Vec<_>>();
if counter_regions.is_empty() {
return Vec::new();
Expand Down

0 comments on commit a7bdfd4

Please sign in to comment.