@@ -51,7 +51,7 @@ impl OpLimits {
5151
5252 /// Worst case opcode count when this element is satisfied
5353 pub fn op_count ( & self ) -> Option < usize > {
54- opt_add ( Some ( self . count ) , self . sat )
54+ self . sat . map ( |sat| self . count + sat)
5555 }
5656}
5757
@@ -821,11 +821,11 @@ impl Property for ExtData {
821821 . iter ( )
822822 . rev ( )
823823 . enumerate ( )
824- . fold ( Some ( 0 ) , |acc, ( i, & ( x, y) ) | {
824+ . try_fold ( 0 , |acc, ( i, & ( x, y) ) | {
825825 if i <= k {
826- opt_add ( acc , x )
826+ x . map ( |x| x + acc )
827827 } else {
828- opt_add ( acc , y )
828+ y . map ( |y| y + acc )
829829 }
830830 } ) ;
831831
@@ -834,11 +834,11 @@ impl Property for ExtData {
834834 . iter ( )
835835 . rev ( )
836836 . enumerate ( )
837- . fold ( Some ( 0 ) , |acc, ( i, & ( x, y) ) | {
837+ . try_fold ( 0 , |acc, ( i, & ( x, y) ) | {
838838 if i <= k {
839- opt_max ( acc , x )
839+ x . map ( |x| cmp :: max ( x , acc ) )
840840 } else {
841- opt_max ( acc , y )
841+ y . map ( |y| cmp :: max ( y , acc ) )
842842 }
843843 } ) ;
844844
@@ -848,11 +848,11 @@ impl Property for ExtData {
848848 max_sat_size_vec
849849 . iter ( )
850850 . enumerate ( )
851- . fold ( Some ( ( 0 , 0 ) ) , |acc, ( i, & ( x, y) ) | {
851+ . try_fold ( ( 0 , 0 ) , |acc, ( i, & ( x, y) ) | {
852852 if i <= k {
853- opt_tuple_add ( acc, x )
853+ x . map ( |x| ( acc. 0 + x . 0 , acc . 1 + x . 1 ) )
854854 } else {
855- opt_tuple_add ( acc, y )
855+ y . map ( |y| ( acc. 0 + y . 0 , acc . 1 + y . 1 ) )
856856 }
857857 } ) ;
858858
@@ -861,11 +861,11 @@ impl Property for ExtData {
861861 ops_count_sat_vec
862862 . iter ( )
863863 . enumerate ( )
864- . fold ( Some ( 0 ) , |acc, ( i, & ( x, y) ) | {
864+ . try_fold ( 0 , |acc, ( i, & ( x, y) ) | {
865865 if i <= k {
866- opt_add ( acc , x )
866+ x . map ( |x| x + acc )
867867 } else {
868- opt_add ( acc , Some ( y) )
868+ Some ( y + acc )
869869 }
870870 } ) ;
871871
@@ -1083,11 +1083,6 @@ fn opt_add(a: Option<usize>, b: Option<usize>) -> Option<usize> {
10831083 a. and_then ( |x| b. map ( |y| x + y) )
10841084}
10851085
1086- /// Returns Some((x0+y0, x1+y1)) is both x and y are Some. Otherwise, returns `None`.
1087- fn opt_tuple_add ( a : Option < ( usize , usize ) > , b : Option < ( usize , usize ) > ) -> Option < ( usize , usize ) > {
1088- a. and_then ( |x| b. map ( |( w, s) | ( w + x. 0 , s + x. 1 ) ) )
1089- }
1090-
10911086#[ cfg( test) ]
10921087mod tests {
10931088 use super :: * ;
0 commit comments