@@ -155,12 +155,14 @@ impl CoverageCounters {
155155        BcbCounter :: Expression  {  id } 
156156    } 
157157
158-     /// Variant of `make_expression`  that makes `lhs` optional and assumes [`Op::Add`] . 
158+     /// Creates a counter  that is the sum of the given counters . 
159159     /// 
160-      /// This is useful when using [`Iterator::fold`] to build an arbitrary-length sum. 
161-      fn  make_sum_expression ( & mut  self ,  lhs :  Option < BcbCounter > ,  rhs :  BcbCounter )  -> BcbCounter  { 
162-         let  Some ( lhs)  = lhs else  {  return  rhs } ; 
163-         self . make_expression ( lhs,  Op :: Add ,  rhs) 
160+      /// Returns `None` if the given list of counters was empty. 
161+      fn  make_sum ( & mut  self ,  counters :  & [ BcbCounter ] )  -> Option < BcbCounter >  { 
162+         counters
163+             . iter ( ) 
164+             . copied ( ) 
165+             . reduce ( |accum,  counter| self . make_expression ( accum,  Op :: Add ,  counter) ) 
164166    } 
165167
166168    pub ( super )  fn  num_counters ( & self )  -> usize  { 
@@ -322,12 +324,9 @@ impl<'a> MakeBcbCounters<'a> {
322324            . filter ( |& to_bcb| to_bcb != expression_to_bcb) 
323325            . map ( |to_bcb| self . get_or_make_edge_counter ( from_bcb,  to_bcb) ) 
324326            . collect :: < Vec < _ > > ( ) ; 
325-         let  sum_of_all_other_out_edges:  BcbCounter  = other_out_edge_counters
326-             . iter ( ) 
327-             . copied ( ) 
328-             . fold ( None ,  |accum,  edge_counter| { 
329-                 Some ( self . coverage_counters . make_sum_expression ( accum,  edge_counter) ) 
330-             } ) 
327+         let  sum_of_all_other_out_edges:  BcbCounter  = self 
328+             . coverage_counters 
329+             . make_sum ( & other_out_edge_counters) 
331330            . expect ( "there must be at least one other out-edge" ) ; 
332331
333332        // Now create an expression for the chosen edge, by taking the counter 
@@ -380,12 +379,9 @@ impl<'a> MakeBcbCounters<'a> {
380379            . copied ( ) 
381380            . map ( |from_bcb| self . get_or_make_edge_counter ( from_bcb,  bcb) ) 
382381            . collect :: < Vec < _ > > ( ) ; 
383-         let  sum_of_in_edges:  BcbCounter  = in_edge_counters
384-             . iter ( ) 
385-             . copied ( ) 
386-             . fold ( None ,  |accum,  edge_counter| { 
387-                 Some ( self . coverage_counters . make_sum_expression ( accum,  edge_counter) ) 
388-             } ) 
382+         let  sum_of_in_edges:  BcbCounter  = self 
383+             . coverage_counters 
384+             . make_sum ( & in_edge_counters) 
389385            . expect ( "there must be at least one in-edge" ) ; 
390386
391387        debug ! ( "{bcb:?} gets a new counter (sum of predecessor counters): {sum_of_in_edges:?}" ) ; 
0 commit comments