coverage: Make the zero counter a constant
This commit is contained in:
parent
0a689c1be8
commit
659575aade
@ -30,11 +30,8 @@ pub struct Counter {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl Counter {
|
impl Counter {
|
||||||
/// Constructs a new `Counter` of kind `Zero`. For this `CounterKind`, the
|
/// A `Counter` of kind `Zero`. For this counter kind, the `id` is not used.
|
||||||
/// `id` is not used.
|
pub(crate) const ZERO: Self = Self { kind: CounterKind::Zero, id: 0 };
|
||||||
pub fn zero() -> Self {
|
|
||||||
Self { kind: CounterKind::Zero, id: 0 }
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Constructs a new `Counter` of kind `CounterValueReference`.
|
/// Constructs a new `Counter` of kind `CounterValueReference`.
|
||||||
pub fn counter_value_reference(counter_id: CounterId) -> Self {
|
pub fn counter_value_reference(counter_id: CounterId) -> Self {
|
||||||
@ -172,7 +169,7 @@ impl CounterMappingRegion {
|
|||||||
) -> Self {
|
) -> Self {
|
||||||
Self {
|
Self {
|
||||||
counter,
|
counter,
|
||||||
false_counter: Counter::zero(),
|
false_counter: Counter::ZERO,
|
||||||
file_id,
|
file_id,
|
||||||
expanded_file_id: 0,
|
expanded_file_id: 0,
|
||||||
start_line,
|
start_line,
|
||||||
@ -220,8 +217,8 @@ impl CounterMappingRegion {
|
|||||||
end_col: u32,
|
end_col: u32,
|
||||||
) -> Self {
|
) -> Self {
|
||||||
Self {
|
Self {
|
||||||
counter: Counter::zero(),
|
counter: Counter::ZERO,
|
||||||
false_counter: Counter::zero(),
|
false_counter: Counter::ZERO,
|
||||||
file_id,
|
file_id,
|
||||||
expanded_file_id,
|
expanded_file_id,
|
||||||
start_line,
|
start_line,
|
||||||
@ -243,8 +240,8 @@ impl CounterMappingRegion {
|
|||||||
end_col: u32,
|
end_col: u32,
|
||||||
) -> Self {
|
) -> Self {
|
||||||
Self {
|
Self {
|
||||||
counter: Counter::zero(),
|
counter: Counter::ZERO,
|
||||||
false_counter: Counter::zero(),
|
false_counter: Counter::ZERO,
|
||||||
file_id,
|
file_id,
|
||||||
expanded_file_id: 0,
|
expanded_file_id: 0,
|
||||||
start_line,
|
start_line,
|
||||||
@ -268,7 +265,7 @@ impl CounterMappingRegion {
|
|||||||
) -> Self {
|
) -> Self {
|
||||||
Self {
|
Self {
|
||||||
counter,
|
counter,
|
||||||
false_counter: Counter::zero(),
|
false_counter: Counter::ZERO,
|
||||||
file_id,
|
file_id,
|
||||||
expanded_file_id: 0,
|
expanded_file_id: 0,
|
||||||
start_line,
|
start_line,
|
||||||
|
@ -191,7 +191,7 @@ impl<'tcx> FunctionCoverage<'tcx> {
|
|||||||
// vector is only complete up to the current `ExpressionIndex`.
|
// vector is only complete up to the current `ExpressionIndex`.
|
||||||
type NewIndexes = IndexSlice<ExpressionId, Option<MappedExpressionIndex>>;
|
type NewIndexes = IndexSlice<ExpressionId, Option<MappedExpressionIndex>>;
|
||||||
let id_to_counter = |new_indexes: &NewIndexes, operand: Operand| match operand {
|
let id_to_counter = |new_indexes: &NewIndexes, operand: Operand| match operand {
|
||||||
Operand::Zero => Some(Counter::zero()),
|
Operand::Zero => Some(Counter::ZERO),
|
||||||
Operand::Counter(id) => Some(Counter::counter_value_reference(id)),
|
Operand::Counter(id) => Some(Counter::counter_value_reference(id)),
|
||||||
Operand::Expression(id) => {
|
Operand::Expression(id) => {
|
||||||
self.expressions
|
self.expressions
|
||||||
@ -201,7 +201,7 @@ impl<'tcx> FunctionCoverage<'tcx> {
|
|||||||
// If an expression was optimized out, assume it would have produced a count
|
// If an expression was optimized out, assume it would have produced a count
|
||||||
// of zero. This ensures that expressions dependent on optimized-out
|
// of zero. This ensures that expressions dependent on optimized-out
|
||||||
// expressions are still valid.
|
// expressions are still valid.
|
||||||
.map_or(Some(Counter::zero()), |_| new_indexes[id].map(Counter::expression))
|
.map_or(Some(Counter::ZERO), |_| new_indexes[id].map(Counter::expression))
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -237,7 +237,7 @@ impl<'tcx> FunctionCoverage<'tcx> {
|
|||||||
original_index={:?}, lhs={:?}, op={:?}, rhs={:?}, region={:?}",
|
original_index={:?}, lhs={:?}, op={:?}, rhs={:?}, region={:?}",
|
||||||
original_index, lhs, op, rhs, optional_region,
|
original_index, lhs, op, rhs, optional_region,
|
||||||
);
|
);
|
||||||
rhs_counter = Counter::zero();
|
rhs_counter = Counter::ZERO;
|
||||||
}
|
}
|
||||||
debug_assert!(
|
debug_assert!(
|
||||||
lhs_counter.is_zero()
|
lhs_counter.is_zero()
|
||||||
@ -306,6 +306,6 @@ impl<'tcx> FunctionCoverage<'tcx> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn unreachable_regions(&self) -> impl Iterator<Item = (Counter, &CodeRegion)> {
|
fn unreachable_regions(&self) -> impl Iterator<Item = (Counter, &CodeRegion)> {
|
||||||
self.unreachable_regions.iter().map(|region| (Counter::zero(), region))
|
self.unreachable_regions.iter().map(|region| (Counter::ZERO, region))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user