@@ -102,57 +102,10 @@ impl CoverageCounters {
102102
103103 fn make_expression(&mut self, lhs: BcbCounter, op: Op, rhs: BcbCounter) -> BcbCounter {
104104 let new_expr = BcbExpression { lhs, op, rhs };
105- *self
106- .expressions_memo
107- .entry(new_expr)
108- .or_insert_with(|| Self::make_expression_inner(&mut self.expressions, new_expr))
109- }
110-
111- /// This is an associated function so that we can call it while borrowing
112- /// `&mut self.expressions_memo`.
113- fn make_expression_inner(
114- expressions: &mut IndexVec<ExpressionId, BcbExpression>,
115- new_expr: BcbExpression,
116- ) -> BcbCounter {
117- // Simplify expressions using basic algebra.
118- //
119- // Some of these cases might not actually occur in practice, depending
120- // on the details of how the instrumentor builds expressions.
121- let BcbExpression { lhs, op, rhs } = new_expr;
122-
123- if let BcbCounter::Expression { id } = lhs {
124- let lhs_expr = &expressions[id];
125-
126- // Simplify `(a - b) + b` to `a`.
127- if lhs_expr.op == Op::Subtract && op == Op::Add && lhs_expr.rhs == rhs {
128- return lhs_expr.lhs;
129- }
130- // Simplify `(a + b) - b` to `a`.
131- if lhs_expr.op == Op::Add && op == Op::Subtract && lhs_expr.rhs == rhs {
132- return lhs_expr.lhs;
133- }
134- // Simplify `(a + b) - a` to `b`.
135- if lhs_expr.op == Op::Add && op == Op::Subtract && lhs_expr.lhs == rhs {
136- return lhs_expr.rhs;
137- }
138- }
139-
140- if let BcbCounter::Expression { id } = rhs {
141- let rhs_expr = &expressions[id];
142-
143- // Simplify `a + (b - a)` to `b`.
144- if op == Op::Add && rhs_expr.op == Op::Subtract && lhs == rhs_expr.rhs {
145- return rhs_expr.lhs;
146- }
147- // Simplify `a - (a - b)` to `b`.
148- if op == Op::Subtract && rhs_expr.op == Op::Subtract && lhs == rhs_expr.lhs {
149- return rhs_expr.rhs;
150- }
151- }
152-
153- // Simplification failed, so actually create the new expression.
154- let id = expressions.push(new_expr);
155- BcbCounter::Expression { id }
105+ *self.expressions_memo.entry(new_expr).or_insert_with(|| {
106+ let id = self.expressions.push(new_expr);
107+ BcbCounter::Expression { id }
108+ })
156109 }
157110
158111 /// Creates a counter that is the sum of the given counters.
0 commit comments