Global Metrics
path: .metrics.halstead.vocabulary
old: 188.0
new: 123.0
path: .metrics.halstead.volume
old: 21069.74830732893
new: 6595.388780072278
path: .metrics.halstead.n1
old: 31.0
new: 29.0
path: .metrics.halstead.n2
old: 157.0
new: 94.0
path: .metrics.halstead.time
old: 145840.5331350535
new: 18764.894555122897
path: .metrics.halstead.effort
old: 2625129.596430963
new: 337768.1019922122
path: .metrics.halstead.N1
old: 1527.0
new: 618.0
path: .metrics.halstead.bugs
old: 6.34326094541453
new: 1.616681620170474
path: .metrics.halstead.length
old: 2789.0
new: 950.0
path: .metrics.halstead.N2
old: 1262.0
new: 332.0
path: .metrics.halstead.difficulty
old: 124.59235668789808
new: 51.212765957446805
path: .metrics.halstead.level
old: 0.00802617453095445
new: 0.01952638138761945
path: .metrics.halstead.purity_ratio
old: 0.4656993700960841
new: 0.7968555799119974
path: .metrics.halstead.estimated_program_length
old: 1298.8355431979785
new: 757.0128009163975
path: .metrics.cyclomatic.average
old: 1.18
new: 3.466666666666667
path: .metrics.cyclomatic.sum
old: 59.0
new: 52.0
path: .metrics.loc.blank
old: 162.0
new: 24.0
path: .metrics.loc.lloc
old: 212.0
new: 92.0
path: .metrics.loc.sloc
old: 822.0
new: 247.0
path: .metrics.loc.cloc
old: 202.0
new: 44.0
path: .metrics.loc.ploc
old: 458.0
new: 179.0
path: .metrics.nargs.average
old: 2.1020408163265305
new: 1.4545454545454546
path: .metrics.nargs.sum
old: 103.0
new: 16.0
path: .metrics.nexits.average
old: 0.04081632653061224
new: 2.1818181818181817
path: .metrics.nexits.sum
old: 2.0
new: 24.0
path: .metrics.mi.mi_visual_studio
old: 0.0
new: 14.069271153843449
path: .metrics.mi.mi_sei
old: -39.38762170192802
new: -5.284545784647754
path: .metrics.mi.mi_original
old: -3.069280918046545
new: 24.058453673072293
path: .metrics.nom.functions
old: 48.0
new: 11.0
path: .metrics.nom.total
old: 49.0
new: 11.0
path: .metrics.nom.closures
old: 1.0
new: 0.0
path: .metrics.cognitive.sum
old: 8.0
new: 60.0
path: .metrics.cognitive.average
old: 0.16326530612244897
new: 5.454545454545454
Spaces Data
Minimal test - lines (233, 243)
path: .spaces[3].metrics.mi.mi_visual_studio
old: 69.10461422706322
new: 59.063539617518
path: .spaces[3].metrics.mi.mi_original
old: 118.16889032827812
new: 100.99865274595578
path: .spaces[3].metrics.mi.mi_sei
old: 94.9844597907548
new: 70.51850275806648
path: .spaces[3].metrics.nargs.sum
old: 3.0
new: 2.0
path: .spaces[3].metrics.nargs.average
old: 3.0
new: 2.0
path: .spaces[3].metrics.cyclomatic.sum
old: 2.0
new: 5.0
path: .spaces[3].metrics.cyclomatic.average
old: 2.0
new: 5.0
path: .spaces[3].metrics.halstead.length
old: 37.0
new: 66.0
path: .spaces[3].metrics.halstead.n2
old: 7.0
new: 12.0
path: .spaces[3].metrics.halstead.volume
old: 157.17331799741265
new: 320.62674567841975
path: .spaces[3].metrics.halstead.level
old: 0.08333333333333333
new: 0.058823529411764705
path: .spaces[3].metrics.halstead.N2
old: 14.0
new: 24.0
path: .spaces[3].metrics.halstead.difficulty
old: 12.0
new: 17.0
path: .spaces[3].metrics.halstead.effort
old: 1886.079815968952
new: 5450.654676533136
path: .spaces[3].metrics.halstead.n1
old: 12.0
new: 17.0
path: .spaces[3].metrics.halstead.purity_ratio
old: 1.6938117422447865
new: 1.7046427016652974
path: .spaces[3].metrics.halstead.bugs
old: 0.05088449361426692
new: 0.10323917472336588
path: .spaces[3].metrics.halstead.time
old: 104.7822119982751
new: 302.8141486962853
path: .spaces[3].metrics.halstead.vocabulary
old: 19.0
new: 29.0
path: .spaces[3].metrics.halstead.N1
old: 23.0
new: 42.0
path: .spaces[3].metrics.halstead.estimated_program_length
old: 62.6710344630571
new: 112.50641830990963
path: .spaces[3].metrics.cognitive.sum
old: 1.0
new: 3.0
path: .spaces[3].metrics.cognitive.average
old: 1.0
new: 3.0
path: .spaces[3].metrics.loc.sloc
old: 5.0
new: 11.0
path: .spaces[3].metrics.loc.blank
old: 0.0
new: 1.0
path: .spaces[3].metrics.loc.ploc
old: 5.0
new: 10.0
path: .spaces[3].metrics.loc.lloc
old: 2.0
new: 3.0
path: .spaces[3].metrics.nexits.sum
old: 0.0
new: 1.0
path: .spaces[3].metrics.nexits.average
old: 0.0
new: 1.0
Code
inline UnsignedT RewindToPriorUTF8Codepoint(const Char* utf8Chars,
UnsignedT index) {
static_assert(std::is_same_v ||
std::is_same_v ||
std::is_same_v,
"UTF-8 data must be in 8-bit units");
static_assert(std::is_unsigned_v, "index type must be unsigned");
while (index > 0 && (utf8Chars[index] & 0xC0) == 0x80) --index;
return index;
}
Minimal test - lines (28, 54)
path: .spaces[0].metrics.loc.ploc
old: 5.0
new: 26.0
path: .spaces[0].metrics.loc.sloc
old: 5.0
new: 27.0
path: .spaces[0].metrics.loc.lloc
old: 2.0
new: 17.0
path: .spaces[0].metrics.loc.cloc
old: 0.0
new: 1.0
path: .spaces[0].metrics.mi.mi_visual_studio
old: 70.03164615489644
new: 46.86964676874349
path: .spaces[0].metrics.mi.mi_original
old: 119.75411492487292
new: 80.14709597455138
path: .spaces[0].metrics.mi.mi_sei
old: 97.16963559555288
new: 55.93787717836836
path: .spaces[0].metrics.cyclomatic.average
old: 1.0
new: 1.4444444444444444
path: .spaces[0].metrics.cyclomatic.sum
old: 1.0
new: 13.0
path: .spaces[0].metrics.nexits.sum
old: 0.0
new: 12.0
path: .spaces[0].metrics.nexits.average
old: 0.0
new: 1.5
path: .spaces[0].metrics.nom.functions
old: 1.0
new: 8.0
path: .spaces[0].metrics.nom.total
old: 1.0
new: 8.0
path: .spaces[0].metrics.cognitive.average
old: 0.0
new: 0.5
path: .spaces[0].metrics.cognitive.sum
old: 0.0
new: 4.0
path: .spaces[0].metrics.halstead.bugs
old: 0.02599890043577348
new: 0.12793725242113052
path: .spaces[0].metrics.halstead.difficulty
old: 5.6875
new: 9.9375
path: .spaces[0].metrics.halstead.estimated_program_length
old: 43.65148445440323
new: 138.56842503028855
path: .spaces[0].metrics.halstead.level
old: 0.17582417582417584
new: 0.10062893081761008
path: .spaces[0].metrics.halstead.time
old: 38.26853600767927
new: 417.7388880093719
path: .spaces[0].metrics.halstead.purity_ratio
old: 1.408112401754943
new: 0.9237895002019236
path: .spaces[0].metrics.halstead.volume
old: 121.11360846386408
new: 756.659117903768
path: .spaces[0].metrics.halstead.length
old: 31.0
new: 150.0
path: .spaces[0].metrics.halstead.N1
old: 18.0
new: 97.0
path: .spaces[0].metrics.halstead.n2
old: 8.0
new: 24.0
path: .spaces[0].metrics.halstead.effort
old: 688.833648138227
new: 7519.299984168694
path: .spaces[0].metrics.halstead.n1
old: 7.0
new: 9.0
path: .spaces[0].metrics.halstead.vocabulary
old: 15.0
new: 33.0
path: .spaces[0].metrics.halstead.N2
old: 13.0
new: 53.0
path: .spaces[0].metrics.nargs.sum
old: 3.0
new: 8.0
path: .spaces[0].metrics.nargs.average
old: 3.0
new: 1.0
Code
class UTF8traits {
public:
static bool isASCII(char aChar) { return (aChar & 0x80) == 0x00; }
static bool isInSeq(char aChar) { return (aChar & 0xC0) == 0x80; }
static bool is2byte(char aChar) { return (aChar & 0xE0) == 0xC0; }
static bool is3byte(char aChar) { return (aChar & 0xF0) == 0xE0; }
static bool is4byte(char aChar) { return (aChar & 0xF8) == 0xF0; }
static bool is5byte(char aChar) { return (aChar & 0xFC) == 0xF8; }
static bool is6byte(char aChar) { return (aChar & 0xFE) == 0xFC; }
// return the number of bytes in a sequence beginning with aChar
static int bytes(char aChar) {
if (isASCII(aChar)) {
return 1;
}
if (is2byte(aChar)) {
return 2;
}
if (is3byte(aChar)) {
return 3;
}
if (is4byte(aChar)) {
return 4;
}
MOZ_ASSERT_UNREACHABLE("should not be used for in-sequence characters");
return 1;
}
};
Minimal test - lines (68, 177)
path: .spaces[1].metrics.cognitive.sum
old: 1.0
new: 45.0
path: .spaces[1].metrics.cognitive.average
old: 1.0
new: 45.0
path: .spaces[1].metrics.nargs.average
old: 2.0
new: 3.0
path: .spaces[1].metrics.nargs.sum
old: 2.0
new: 3.0
path: .spaces[1].metrics.mi.mi_original
old: 105.08040572795063
new: 46.74443166840322
path: .spaces[1].metrics.mi.mi_visual_studio
old: 61.45052966546821
new: 27.335924952282586
path: .spaces[1].metrics.mi.mi_sei
old: 76.1017679651108
new: 8.941488008911845
path: .spaces[1].metrics.loc.blank
old: 1.0
new: 9.0
path: .spaces[1].metrics.loc.lloc
old: 5.0
new: 56.0
path: .spaces[1].metrics.loc.ploc
old: 9.0
new: 97.0
path: .spaces[1].metrics.loc.sloc
old: 10.0
new: 110.0
path: .spaces[1].metrics.loc.cloc
old: 0.0
new: 4.0
path: .spaces[1].metrics.halstead.length
old: 52.0
new: 542.0
path: .spaces[1].metrics.halstead.vocabulary
old: 20.0
new: 68.0
path: .spaces[1].metrics.halstead.level
old: 0.06818181818181819
new: 0.020257826887661146
path: .spaces[1].metrics.halstead.N2
old: 24.0
new: 181.0
path: .spaces[1].metrics.halstead.n1
old: 11.0
new: 24.0
path: .spaces[1].metrics.halstead.N1
old: 28.0
new: 361.0
path: .spaces[1].metrics.halstead.difficulty
old: 14.666666666666666
new: 49.36363636363637
path: .spaces[1].metrics.halstead.effort
old: 3296.190493700762
new: 162870.62172336565
path: .spaces[1].metrics.halstead.n2
old: 9.0
new: 44.0
path: .spaces[1].metrics.halstead.time
old: 183.12169409448677
new: 9048.367873520314
path: .spaces[1].metrics.halstead.purity_ratio
old: 1.28044370803829
new: 0.6462252605855144
path: .spaces[1].metrics.halstead.bugs
old: 0.07382786005219222
new: 0.994124052228488
path: .spaces[1].metrics.halstead.volume
old: 224.74026093414287
new: 3299.4048599576836
path: .spaces[1].metrics.halstead.estimated_program_length
old: 66.58307281799108
new: 350.2540912373488
path: .spaces[1].metrics.nexits.sum
old: 0.0
new: 8.0
path: .spaces[1].metrics.nexits.average
old: 0.0
new: 8.0
path: .spaces[1].metrics.cyclomatic.average
old: 2.0
new: 13.0
path: .spaces[1].metrics.cyclomatic.sum
old: 2.0
new: 26.0
Code
class UTF8CharEnumerator {
public:
static inline char32_t NextChar(const char** aBuffer, const char* aEnd,
bool* aErr = nullptr) {
MOZ_ASSERT(aBuffer, "null buffer pointer pointer");
MOZ_ASSERT(aEnd, "null end pointer");
const unsigned char* p = reinterpret_cast(*aBuffer);
const unsigned char* end = reinterpret_cast(aEnd);
MOZ_ASSERT(p, "null buffer");
MOZ_ASSERT(p < end, "Bogus range");
unsigned char first = *p;
++p;
if (MOZ_LIKELY(first < 0x80U)) {
*aBuffer = reinterpret_cast(p);
return first;
}
// Unsigned underflow is defined behavior
if (MOZ_UNLIKELY((p == end) || ((first - 0xC2U) >= (0xF5U - 0xC2U)))) {
*aBuffer = reinterpret_cast(p);
if (aErr) {
*aErr = true;
}
return 0xFFFDU;
}
unsigned char second = *p;
if (first < 0xE0U) {
// Two-byte
if (MOZ_LIKELY((second & 0xC0U) == 0x80U)) {
++p;
*aBuffer = reinterpret_cast(p);
return ((uint32_t(first) & 0x1FU) << 6) | (uint32_t(second) & 0x3FU);
}
*aBuffer = reinterpret_cast(p);
if (aErr) {
*aErr = true;
}
return 0xFFFDU;
}
if (MOZ_LIKELY(first < 0xF0U)) {
// Three-byte
unsigned char lower = 0x80U;
unsigned char upper = 0xBFU;
if (first == 0xE0U) {
lower = 0xA0U;
} else if (first == 0xEDU) {
upper = 0x9FU;
}
if (MOZ_LIKELY(second >= lower && second <= upper)) {
++p;
if (MOZ_LIKELY(p != end)) {
unsigned char third = *p;
if (MOZ_LIKELY((third & 0xC0U) == 0x80U)) {
++p;
*aBuffer = reinterpret_cast(p);
return ((uint32_t(first) & 0xFU) << 12) |
((uint32_t(second) & 0x3FU) << 6) |
(uint32_t(third) & 0x3FU);
}
}
}
*aBuffer = reinterpret_cast(p);
if (aErr) {
*aErr = true;
}
return 0xFFFDU;
}
// Four-byte
unsigned char lower = 0x80U;
unsigned char upper = 0xBFU;
if (first == 0xF0U) {
lower = 0x90U;
} else if (first == 0xF4U) {
upper = 0x8FU;
}
if (MOZ_LIKELY(second >= lower && second <= upper)) {
++p;
if (MOZ_LIKELY(p != end)) {
unsigned char third = *p;
if (MOZ_LIKELY((third & 0xC0U) == 0x80U)) {
++p;
if (MOZ_LIKELY(p != end)) {
unsigned char fourth = *p;
if (MOZ_LIKELY((fourth & 0xC0U) == 0x80U)) {
++p;
*aBuffer = reinterpret_cast(p);
return ((uint32_t(first) & 0x7U) << 18) |
((uint32_t(second) & 0x3FU) << 12) |
((uint32_t(third) & 0x3FU) << 6) |
(uint32_t(fourth) & 0x3FU);
}
}
}
}
}
*aBuffer = reinterpret_cast(p);
if (aErr) {
*aErr = true;
}
return 0xFFFDU;
}
};
Minimal test - lines (190, 230)
path: .spaces[2].metrics.nexits.sum
old: 1.0
new: 3.0
path: .spaces[2].metrics.nexits.average
old: 1.0
new: 3.0
path: .spaces[2].metrics.cyclomatic.sum
old: 1.0
new: 7.0
path: .spaces[2].metrics.cyclomatic.average
old: 1.0
new: 3.5
path: .spaces[2].metrics.mi.mi_visual_studio
old: 72.85229283872809
new: 43.100169582636184
path: .spaces[2].metrics.mi.mi_original
old: 124.57742075422505
new: 73.70128998630787
path: .spaces[2].metrics.mi.mi_sei
old: 104.12819499625
new: 57.09012107490486
path: .spaces[2].metrics.nargs.average
old: 1.0
new: 3.0
path: .spaces[2].metrics.nargs.sum
old: 1.0
new: 3.0
path: .spaces[2].metrics.cognitive.average
old: 0.0
new: 8.0
path: .spaces[2].metrics.cognitive.sum
old: 0.0
new: 8.0
path: .spaces[2].metrics.loc.lloc
old: 1.0
new: 16.0
path: .spaces[2].metrics.loc.cloc
old: 0.0
new: 5.0
path: .spaces[2].metrics.loc.blank
old: 0.0
new: 4.0
path: .spaces[2].metrics.loc.ploc
old: 4.0
new: 32.0
path: .spaces[2].metrics.loc.sloc
old: 4.0
new: 41.0
path: .spaces[2].metrics.halstead.purity_ratio
old: 2.0693078449769615
new: 1.0761497095538914
path: .spaces[2].metrics.halstead.level
old: 0.12987012987012986
new: 0.043010752688172046
path: .spaces[2].metrics.halstead.bugs
old: 0.027251268165690797
new: 0.2582438459641226
path: .spaces[2].metrics.halstead.volume
old: 96.0
new: 927.4785967179467
path: .spaces[2].metrics.halstead.time
old: 41.06666666666667
new: 1197.993187427348
path: .spaces[2].metrics.halstead.difficulty
old: 7.7
new: 23.25
path: .spaces[2].metrics.halstead.estimated_program_length
old: 49.66338827944708
new: 185.09775004326937
path: .spaces[2].metrics.halstead.N1
old: 17.0
new: 110.0
path: .spaces[2].metrics.halstead.n2
old: 5.0
new: 24.0
path: .spaces[2].metrics.halstead.n1
old: 11.0
new: 18.0
path: .spaces[2].metrics.halstead.N2
old: 7.0
new: 62.0
path: .spaces[2].metrics.halstead.effort
old: 739.2
new: 21563.877373692263
path: .spaces[2].metrics.halstead.length
old: 24.0
new: 172.0
path: .spaces[2].metrics.halstead.vocabulary
old: 16.0
new: 42.0
Code
class UTF16CharEnumerator {
public:
static inline char32_t NextChar(const char16_t** aBuffer,
const char16_t* aEnd, bool* aErr = nullptr) {
MOZ_ASSERT(aBuffer, "null buffer pointer pointer");
MOZ_ASSERT(aEnd, "null end pointer");
const char16_t* p = *aBuffer;
MOZ_ASSERT(p, "null buffer");
MOZ_ASSERT(p < aEnd, "Bogus range");
char16_t c = *p++;
// Let's use encoding_rs-style code golf here.
// Unsigned underflow is defined behavior
char16_t cMinusSurrogateStart = c - 0xD800U;
if (MOZ_LIKELY(cMinusSurrogateStart > (0xDFFFU - 0xD800U))) {
*aBuffer = p;
return c;
}
if (MOZ_LIKELY(cMinusSurrogateStart <= (0xDBFFU - 0xD800U))) {
// High surrogate
if (MOZ_LIKELY(p != aEnd)) {
char16_t second = *p;
// Unsigned underflow is defined behavior
if (MOZ_LIKELY((second - 0xDC00U) <= (0xDFFFU - 0xDC00U))) {
*aBuffer = ++p;
return (uint32_t(c) << 10) + uint32_t(second) -
(((0xD800U << 10) - 0x10000U) + 0xDC00U);
}
}
}
// Unpaired surrogate
*aBuffer = p;
if (aErr) {
*aErr = true;
}
return 0xFFFDU;
}
};