@@ -1096,20 +1096,31 @@ void SourceCoverageViewHTML::renderBranchView(raw_ostream &OS, BranchView &BRV,
1096
1096
if (getOptions ().Debug )
1097
1097
errs () << " Branch at line " << BRV.getLine () << ' \n ' ;
1098
1098
1099
+ auto BranchCount = [&](StringRef Label, uint64_t Count, bool Folded,
1100
+ double Total) {
1101
+ if (Folded)
1102
+ return std::string{" Folded" };
1103
+
1104
+ std::string Str;
1105
+ raw_string_ostream OS (Str);
1106
+
1107
+ OS << tag (" span" , Label, (Count ? " None" : " red branch" )) << " : " ;
1108
+ if (getOptions ().ShowBranchCounts )
1109
+ OS << tag (" span" , formatCount (Count),
1110
+ (Count ? " covered-line" : " uncovered-line" ));
1111
+ else
1112
+ OS << format (" %0.2f" , (Total != 0 ? 100.0 * Count / Total : 0.0 )) << " %" ;
1113
+
1114
+ return Str;
1115
+ };
1116
+
1099
1117
OS << BeginExpansionDiv;
1100
1118
OS << BeginPre;
1101
1119
for (const auto &R : BRV.Regions ) {
1102
- // Calculate TruePercent and False Percent.
1103
- double TruePercent = 0.0 ;
1104
- double FalsePercent = 0.0 ;
1105
- // FIXME: It may overflow when the data is too large, but I have not
1106
- // encountered it in actual use, and not sure whether to use __uint128_t.
1107
- uint64_t Total = R.ExecutionCount + R.FalseExecutionCount ;
1108
-
1109
- if (!getOptions ().ShowBranchCounts && Total != 0 ) {
1110
- TruePercent = ((double )(R.ExecutionCount ) / (double )Total) * 100.0 ;
1111
- FalsePercent = ((double )(R.FalseExecutionCount ) / (double )Total) * 100.0 ;
1112
- }
1120
+ // This can be `double` since it is only used as a denominator.
1121
+ // FIXME: It is still inaccurate if Count is greater than (1LL << 53).
1122
+ double Total =
1123
+ static_cast <double >(R.ExecutionCount ) + R.FalseExecutionCount ;
1113
1124
1114
1125
// Display Line + Column.
1115
1126
std::string LineNoStr = utostr (uint64_t (R.LineStart ));
@@ -1128,40 +1139,9 @@ void SourceCoverageViewHTML::renderBranchView(raw_ostream &OS, BranchView &BRV,
1128
1139
continue ;
1129
1140
}
1130
1141
1131
- // Display TrueCount or TruePercent.
1132
- std::string TrueColor =
1133
- (R.TrueFolded || R.ExecutionCount ? " None" : " red branch" );
1134
- std::string TrueCovClass =
1135
- (R.TrueFolded || R.ExecutionCount > 0 ? " covered-line"
1136
- : " uncovered-line" );
1137
-
1138
- if (R.TrueFolded )
1139
- OS << " Folded, " ;
1140
- else {
1141
- OS << tag (" span" , " True" , TrueColor) << " : " ;
1142
- if (getOptions ().ShowBranchCounts )
1143
- OS << tag (" span" , formatCount (R.ExecutionCount ), TrueCovClass) << " , " ;
1144
- else
1145
- OS << format (" %0.2f" , TruePercent) << " %, " ;
1146
- }
1147
-
1148
- // Display FalseCount or FalsePercent.
1149
- std::string FalseColor =
1150
- (R.FalseFolded || R.FalseExecutionCount ? " None" : " red branch" );
1151
- std::string FalseCovClass =
1152
- (R.FalseFolded || R.FalseExecutionCount > 0 ? " covered-line"
1153
- : " uncovered-line" );
1154
-
1155
- if (R.FalseFolded )
1156
- OS << " Folded]\n " ;
1157
- else {
1158
- OS << tag (" span" , " False" , FalseColor) << " : " ;
1159
- if (getOptions ().ShowBranchCounts )
1160
- OS << tag (" span" , formatCount (R.FalseExecutionCount ), FalseCovClass)
1161
- << " ]\n " ;
1162
- else
1163
- OS << format (" %0.2f" , FalsePercent) << " %]\n " ;
1164
- }
1142
+ OS << BranchCount (" True" , R.ExecutionCount , R.TrueFolded , Total) << " , "
1143
+ << BranchCount (" False" , R.FalseExecutionCount , R.FalseFolded , Total)
1144
+ << " ]\n " ;
1165
1145
}
1166
1146
OS << EndPre;
1167
1147
OS << EndExpansionDiv;
0 commit comments