Global Metrics

path: .metrics.cognitive.sum
old: 22.0
new: 2.0

path: .metrics.cognitive.average
old: 1.2222222222222223
new: 0.16666666666666666

path: .metrics.halstead.estimated_program_length
old: 1083.440109377309
new: 350.17943238760677

path: .metrics.halstead.time
old: 15963.614951924486
new: 9232.340152399567

path: .metrics.halstead.N2
old: 352.0
new: 236.0

path: .metrics.halstead.n2
old: 132.0
new: 49.0

path: .metrics.halstead.N1
old: 594.0
new: 396.0

path: .metrics.halstead.vocabulary
old: 163.0
new: 67.0

path: .metrics.halstead.purity_ratio
old: 1.1452855278829903
new: 0.5540813803601373

path: .metrics.halstead.effort
old: 287345.06913464074
new: 166182.12274319222

path: .metrics.halstead.volume
old: 6951.896833902599
new: 3833.768368369312

path: .metrics.halstead.level
old: 0.024193548387096777
new: 0.023069679849340868

path: .metrics.halstead.difficulty
old: 41.333333333333336
new: 43.3469387755102

path: .metrics.halstead.length
old: 946.0
new: 632.0

path: .metrics.halstead.n1
old: 31.0
new: 18.0

path: .metrics.halstead.bugs
old: 1.4514917707929438
new: 1.0075538806348463

path: .metrics.nargs.sum
old: 22.0
new: 18.0

path: .metrics.nargs.average
old: 1.2222222222222223
new: 1.5

path: .metrics.mi.mi_original
old: 24.702472549723836
new: 40.81384595865951

path: .metrics.mi.mi_sei
old: -9.277440171951636
new: 18.9447976006928

path: .metrics.mi.mi_visual_studio
old: 14.44589037995546
new: 23.867746174654688

path: .metrics.cyclomatic.average
old: 1.826086956521739
new: 1.1

path: .metrics.cyclomatic.sum
old: 42.0
new: 22.0

path: .metrics.nexits.average
old: 1.6111111111111112
new: 0.6666666666666666

path: .metrics.nexits.sum
old: 29.0
new: 8.0

path: .metrics.loc.lloc
old: 72.0
new: 28.0

path: .metrics.loc.cloc
old: 35.0
new: 36.0

path: .metrics.loc.blank
old: 44.0
new: 22.0

path: .metrics.loc.sloc
old: 269.0
new: 160.0

path: .metrics.loc.ploc
old: 190.0
new: 102.0

path: .metrics.nom.functions
old: 18.0
new: 12.0

path: .metrics.nom.total
old: 18.0
new: 12.0

Spaces Data

Minimal test - lines (28, 41)

path: .spaces[0].spaces[0].metrics.nexits.average
old: 1.6111111111111112
new: 0.5

path: .spaces[0].spaces[0].metrics.nexits.sum
old: 29.0
new: 1.0

path: .spaces[0].spaces[0].metrics.halstead.bugs
old: 1.468284384958683
new: 0.11771493261813146

path: .spaces[0].spaces[0].metrics.halstead.N2
old: 345.0
new: 30.0

path: .spaces[0].spaces[0].metrics.halstead.level
old: 0.02337540906965872
new: 0.062222222222222213

path: .spaces[0].spaces[0].metrics.halstead.purity_ratio
old: 1.0920075919027228
new: 1.3165450334462852

path: .spaces[0].spaces[0].metrics.halstead.time
old: 16241.444305205863
new: 368.6860576659318

path: .spaces[0].spaces[0].metrics.halstead.volume
old: 6833.707281292789
new: 412.9283845858436

path: .spaces[0].spaces[0].metrics.halstead.N1
old: 593.0
new: 55.0

path: .spaces[0].spaces[0].metrics.halstead.difficulty
old: 42.78
new: 16.071428571428573

path: .spaces[0].spaces[0].metrics.halstead.length
old: 938.0
new: 85.0

path: .spaces[0].spaces[0].metrics.halstead.effort
old: 292345.99749370554
new: 6636.349037986773

path: .spaces[0].spaces[0].metrics.halstead.n2
old: 125.0
new: 14.0

path: .spaces[0].spaces[0].metrics.halstead.vocabulary
old: 156.0
new: 29.0

path: .spaces[0].spaces[0].metrics.halstead.estimated_program_length
old: 1024.303121204754
new: 111.90632784293425

path: .spaces[0].spaces[0].metrics.halstead.n1
old: 31.0
new: 15.0

path: .spaces[0].spaces[0].metrics.cyclomatic.sum
old: 40.0
new: 3.0

path: .spaces[0].spaces[0].metrics.cyclomatic.average
old: 1.9047619047619049
new: 1.0

path: .spaces[0].spaces[0].metrics.cognitive.average
old: 1.2222222222222223
new: 0.0

path: .spaces[0].spaces[0].metrics.cognitive.sum
old: 22.0
new: 0.0

path: .spaces[0].spaces[0].metrics.loc.sloc
old: 251.0
new: 14.0

path: .spaces[0].spaces[0].metrics.loc.blank
old: 42.0
new: 1.0

path: .spaces[0].spaces[0].metrics.loc.ploc
old: 181.0
new: 12.0

path: .spaces[0].spaces[0].metrics.loc.cloc
old: 28.0
new: 1.0

path: .spaces[0].spaces[0].metrics.loc.lloc
old: 72.0
new: 3.0

path: .spaces[0].spaces[0].metrics.nom.functions
old: 18.0
new: 2.0

path: .spaces[0].spaces[0].metrics.nom.total
old: 18.0
new: 2.0

path: .spaces[0].spaces[0].metrics.nargs.sum
old: 22.0
new: 3.0

path: .spaces[0].spaces[0].metrics.nargs.average
old: 1.2222222222222223
new: 1.5

path: .spaces[0].spaces[0].metrics.mi.mi_sei
old: -8.846747849729898
new: 83.55969303578966

path: .spaces[0].spaces[0].metrics.mi.mi_visual_studio
old: 15.42317243917604
new: 56.27850616977193

path: .spaces[0].spaces[0].metrics.mi.mi_original
old: 26.373624870991023
new: 96.23624555031

Code

struct ProfileBufferEntryWriter::Serializer> {
  static Length Bytes(const nsTString& aS) {
    const auto length = aS.Length();
    return ProfileBufferEntryWriter::ULEB128Size(length) +
           static_cast(length * sizeof(CHAR));
  }

  static void Write(ProfileBufferEntryWriter& aEW, const nsTString& aS) {
    const auto length = aS.Length();
    aEW.WriteULEB128(length);
    // Copy the bytes from the string's buffer.
    aEW.WriteBytes(aS.Data(), length * sizeof(CHAR));
  }
};

Minimal test - lines (35, 40)

path: .spaces[0].spaces[0].spaces[1].metrics.nexits.average
old: 2.0
new: 0.0

path: .spaces[0].spaces[0].spaces[1].metrics.nexits.sum
old: 6.0
new: 0.0

path: .spaces[0].spaces[0].spaces[1].metrics.halstead.vocabulary
old: 63.0
new: 22.0

path: .spaces[0].spaces[0].spaces[1].metrics.halstead.level
old: 0.05972222222222222
new: 0.10416666666666669

path: .spaces[0].spaces[0].spaces[1].metrics.halstead.difficulty
old: 16.74418604651163
new: 9.6

path: .spaces[0].spaces[0].spaces[1].metrics.halstead.effort
old: 20217.106792414605
new: 1798.0428286345582

path: .spaces[0].spaces[0].spaces[1].metrics.halstead.estimated_program_length
old: 319.76794634993746
new: 76.2388309575275

path: .spaces[0].spaces[0].spaces[1].metrics.halstead.N1
old: 130.0
new: 26.0

path: .spaces[0].spaces[0].spaces[1].metrics.halstead.volume
old: 1207.4105445469831
new: 187.29612798276648

path: .spaces[0].spaces[0].spaces[1].metrics.halstead.n2
old: 43.0
new: 10.0

path: .spaces[0].spaces[0].spaces[1].metrics.halstead.n1
old: 20.0
new: 12.0

path: .spaces[0].spaces[0].spaces[1].metrics.halstead.purity_ratio
old: 1.58300963539573
new: 1.815210260893512

path: .spaces[0].spaces[0].spaces[1].metrics.halstead.time
old: 1123.1725995785891
new: 99.89126825747546

path: .spaces[0].spaces[0].spaces[1].metrics.halstead.N2
old: 72.0
new: 16.0

path: .spaces[0].spaces[0].spaces[1].metrics.halstead.bugs
old: 0.24737629575723996
new: 0.049288480932635145

path: .spaces[0].spaces[0].spaces[1].metrics.halstead.length
old: 202.0
new: 42.0

path: .spaces[0].spaces[0].spaces[1].metrics.cognitive.sum
old: 6.0
new: 0.0

path: .spaces[0].spaces[0].spaces[1].metrics.cognitive.average
old: 2.0
new: 0.0

path: .spaces[0].spaces[0].spaces[1].metrics.mi.mi_sei
old: 51.5616026458824
new: 119.1942415737467

path: .spaces[0].spaces[0].spaces[1].metrics.mi.mi_visual_studio
old: 38.39966680848912
new: 66.97865715151242

path: .spaces[0].spaces[0].spaces[1].metrics.mi.mi_original
old: 65.6634302425164
new: 114.53350372908623

path: .spaces[0].spaces[0].spaces[1].metrics.cyclomatic.average
old: 2.0
new: 1.0

path: .spaces[0].spaces[0].spaces[1].metrics.cyclomatic.sum
old: 8.0
new: 1.0

path: .spaces[0].spaces[0].spaces[1].metrics.nargs.average
old: 0.6666666666666666
new: 2.0

path: .spaces[0].spaces[0].spaces[1].metrics.loc.cloc
old: 12.0
new: 1.0

path: .spaces[0].spaces[0].spaces[1].metrics.loc.sloc
old: 61.0
new: 6.0

path: .spaces[0].spaces[0].spaces[1].metrics.loc.blank
old: 10.0
new: 0.0

path: .spaces[0].spaces[0].spaces[1].metrics.loc.ploc
old: 39.0
new: 5.0

path: .spaces[0].spaces[0].spaces[1].metrics.loc.lloc
old: 13.0
new: 2.0

path: .spaces[0].spaces[0].spaces[1].metrics.nom.total
old: 3.0
new: 1.0

path: .spaces[0].spaces[0].spaces[1].metrics.nom.functions
old: 3.0
new: 1.0

Code

  static void Write(ProfileBufferEntryWriter& aEW, const nsTString& aS) {
    const auto length = aS.Length();
    aEW.WriteULEB128(length);
    // Copy the bytes from the string's buffer.
    aEW.WriteBytes(aS.Data(), length * sizeof(CHAR));
  }

Minimal test - lines (29, 33)

path: .spaces[0].spaces[0].spaces[0].metrics.loc.ploc
old: 29.0
new: 5.0

path: .spaces[0].spaces[0].spaces[0].metrics.loc.sloc
old: 47.0
new: 5.0

path: .spaces[0].spaces[0].spaces[0].metrics.loc.blank
old: 6.0
new: 0.0

path: .spaces[0].spaces[0].spaces[0].metrics.loc.cloc
old: 12.0
new: 0.0

path: .spaces[0].spaces[0].spaces[0].metrics.loc.lloc
old: 13.0
new: 1.0

path: .spaces[0].spaces[0].spaces[0].metrics.nargs.average
old: 0.4
new: 1.0

path: .spaces[0].spaces[0].spaces[0].metrics.nargs.sum
old: 2.0
new: 1.0

path: .spaces[0].spaces[0].spaces[0].metrics.nexits.average
old: 1.2
new: 1.0

path: .spaces[0].spaces[0].spaces[0].metrics.nexits.sum
old: 6.0
new: 1.0

path: .spaces[0].spaces[0].spaces[0].metrics.halstead.vocabulary
old: 47.0
new: 21.0

path: .spaces[0].spaces[0].spaces[0].metrics.halstead.N1
old: 91.0
new: 22.0

path: .spaces[0].spaces[0].spaces[0].metrics.halstead.N2
old: 49.0
new: 12.0

path: .spaces[0].spaces[0].spaces[0].metrics.halstead.n2
old: 28.0
new: 7.0

path: .spaces[0].spaces[0].spaces[0].metrics.halstead.purity_ratio
old: 1.5379754326645787
new: 2.1457192165649905

path: .spaces[0].spaces[0].spaces[0].metrics.halstead.n1
old: 19.0
new: 14.0

path: .spaces[0].spaces[0].spaces[0].metrics.halstead.volume
old: 777.6424392348692
new: 149.33879237447786

path: .spaces[0].spaces[0].spaces[0].metrics.halstead.effort
old: 12928.3055522797
new: 1792.0655084937343

path: .spaces[0].spaces[0].spaces[0].metrics.halstead.time
old: 718.2391973488723
new: 99.55919491631856

path: .spaces[0].spaces[0].spaces[0].metrics.halstead.length
old: 140.0
new: 34.0

path: .spaces[0].spaces[0].spaces[0].metrics.halstead.estimated_program_length
old: 215.31656057304104
new: 72.95445336320968

path: .spaces[0].spaces[0].spaces[0].metrics.halstead.difficulty
old: 16.625
new: 12.0

path: .spaces[0].spaces[0].spaces[0].metrics.halstead.level
old: 0.06015037593984962
new: 0.08333333333333333

path: .spaces[0].spaces[0].spaces[0].metrics.halstead.bugs
old: 0.1836142926072735
new: 0.049179185610912515

path: .spaces[0].spaces[0].spaces[0].metrics.mi.mi_visual_studio
old: 42.07311189603111
new: 69.39460515961812

path: .spaces[0].spaces[0].spaces[0].metrics.mi.mi_sei
old: 64.27338937773732
new: 95.59805003266284

path: .spaces[0].spaces[0].spaces[0].metrics.mi.mi_original
old: 71.9450213422132
new: 118.66477482294698

path: .spaces[0].spaces[0].spaces[0].metrics.nom.total
old: 5.0
new: 1.0

path: .spaces[0].spaces[0].spaces[0].metrics.nom.functions
old: 5.0
new: 1.0

path: .spaces[0].spaces[0].spaces[0].metrics.cognitive.average
old: 0.8
new: 0.0

path: .spaces[0].spaces[0].spaces[0].metrics.cognitive.sum
old: 4.0
new: 0.0

path: .spaces[0].spaces[0].spaces[0].metrics.cyclomatic.average
old: 1.5
new: 1.0

path: .spaces[0].spaces[0].spaces[0].metrics.cyclomatic.sum
old: 9.0
new: 1.0

Code

  static Length Bytes(const nsTString& aS) {
    const auto length = aS.Length();
    return ProfileBufferEntryWriter::ULEB128Size(length) +
           static_cast(length * sizeof(CHAR));
  }

Minimal test - lines (16, 158)

path: .spaces[0].metrics.mi.mi_visual_studio
old: 15.203158788676191
new: 25.152043653385512

path: .spaces[0].metrics.mi.mi_sei
old: -8.980960727468759
new: 20.60853618787845

path: .spaces[0].metrics.mi.mi_original
old: 25.99740152863629
new: 43.00999464728922

path: .spaces[0].metrics.nargs.average
old: 1.2222222222222223
new: 1.5

path: .spaces[0].metrics.nargs.sum
old: 22.0
new: 18.0

path: .spaces[0].metrics.nexits.sum
old: 29.0
new: 8.0

path: .spaces[0].metrics.nexits.average
old: 1.6111111111111112
new: 0.6666666666666666

path: .spaces[0].metrics.halstead.N1
old: 594.0
new: 396.0

path: .spaces[0].metrics.halstead.difficulty
old: 42.56349206349206
new: 47.04545454545455

path: .spaces[0].metrics.halstead.vocabulary
old: 157.0
new: 62.0

path: .spaces[0].metrics.halstead.level
old: 0.023494312884579528
new: 0.021256038647342993

path: .spaces[0].metrics.halstead.effort
old: 291855.4604105353
new: 175353.78779376182

path: .spaces[0].metrics.halstead.purity_ratio
old: 1.0986354850882794
new: 0.5036320147699723

path: .spaces[0].metrics.halstead.length
old: 940.0
new: 626.0

path: .spaces[0].metrics.halstead.bugs
old: 1.4666414697889218
new: 1.044292549598914

path: .spaces[0].metrics.halstead.time
old: 16214.192245029735
new: 9741.877099653437

path: .spaces[0].metrics.halstead.n1
old: 31.0
new: 18.0

path: .spaces[0].metrics.halstead.volume
old: 6856.943503958129
new: 3727.326890302183

path: .spaces[0].metrics.halstead.estimated_program_length
old: 1032.7173559829826
new: 315.2736412460027

path: .spaces[0].metrics.halstead.n2
old: 126.0
new: 44.0

path: .spaces[0].metrics.halstead.N2
old: 346.0
new: 230.0

path: .spaces[0].metrics.nom.total
old: 18.0
new: 12.0

path: .spaces[0].metrics.nom.functions
old: 18.0
new: 12.0

path: .spaces[0].metrics.cyclomatic.sum
old: 41.0
new: 21.0

path: .spaces[0].metrics.cyclomatic.average
old: 1.8636363636363635
new: 1.105263157894737

path: .spaces[0].metrics.cognitive.sum
old: 22.0
new: 2.0

path: .spaces[0].metrics.cognitive.average
old: 1.2222222222222223
new: 0.16666666666666666

path: .spaces[0].metrics.loc.lloc
old: 72.0
new: 28.0

path: .spaces[0].metrics.loc.ploc
old: 183.0
new: 95.0

path: .spaces[0].metrics.loc.blank
old: 41.0
new: 19.0

path: .spaces[0].metrics.loc.sloc
old: 253.0
new: 143.0

Code

namespace mozilla {

// ----------------------------------------------------------------------------
// ns[C]String

// nsString or nsCString contents are serialized as the number of bytes (encoded
// as ULEB128) and all the characters in the string. The terminal '\0' is
// omitted.
// Make sure you write and read with the same character type!
//
// Usage: `nsCString s = ...; aEW.WriteObject(s);`
template 
struct ProfileBufferEntryWriter::Serializer> {
  static Length Bytes(const nsTString& aS) {
    const auto length = aS.Length();
    return ProfileBufferEntryWriter::ULEB128Size(length) +
           static_cast(length * sizeof(CHAR));
  }

  static void Write(ProfileBufferEntryWriter& aEW, const nsTString& aS) {
    const auto length = aS.Length();
    aEW.WriteULEB128(length);
    // Copy the bytes from the string's buffer.
    aEW.WriteBytes(aS.Data(), length * sizeof(CHAR));
  }
};

template 
struct ProfileBufferEntryReader::Deserializer> {
  static void ReadInto(ProfileBufferEntryReader& aER, nsTString& aS) {
    aS = Read(aER);
  }

  static nsTString Read(ProfileBufferEntryReader& aER) {
    const Length length = aER.ReadULEB128();
    nsTString s;
    // BulkWrite is the most efficient way to copy bytes into the target string.
    auto writerOrErr = s.BulkWrite(length, 0, true);
    MOZ_RELEASE_ASSERT(!writerOrErr.isErr());

    auto writer = writerOrErr.unwrap();

    aER.ReadBytes(writer.Elements(), length * sizeof(CHAR));
    writer.Finish(length, true);
    return s;
  }
};

// ----------------------------------------------------------------------------
// nsAuto[C]String

// nsAuto[C]String contents are serialized as the number of bytes (encoded as
// ULEB128) and all the characters in the string. The terminal '\0' is omitted.
// Make sure you write and read with the same character type!
//
// Usage: `nsAutoCString s = ...; aEW.WriteObject(s);`
template 
struct ProfileBufferEntryWriter::Serializer> {
  static Length Bytes(const nsTAutoStringN& aS) {
    const auto length = aS.Length();
    return ProfileBufferEntryWriter::ULEB128Size(length) +
           static_cast(length * sizeof(CHAR));
  }

  static void Write(ProfileBufferEntryWriter& aEW,
                    const nsTAutoStringN& aS) {
    const auto length = aS.Length();
    aEW.WriteULEB128(length);
    // Copy the bytes from the string's buffer.
    aEW.WriteBytes(aS.BeginReading(), length * sizeof(CHAR));
  }
};

template 
struct ProfileBufferEntryReader::Deserializer> {
  static void ReadInto(ProfileBufferEntryReader& aER,
                       nsTAutoStringN& aS) {
    aS = Read(aER);
  }

  static nsTAutoStringN Read(ProfileBufferEntryReader& aER) {
    const auto length = aER.ReadULEB128();
    nsTAutoStringN s;
    // BulkWrite is the most efficient way to copy bytes into the target string.
    auto writerOrErr = s.BulkWrite(length, 0, true);
    MOZ_RELEASE_ASSERT(!writerOrErr.isErr());

    auto writer = writerOrErr.unwrap();
    aER.ReadBytes(writer.Elements(), length * sizeof(CHAR));
    writer.Finish(length, true);
    return s;
  }
};

// ----------------------------------------------------------------------------
// JS::UniqueChars

// JS::UniqueChars contents are serialized as the number of bytes (encoded as
// ULEB128) and all the characters in the string. The terminal '\0' is omitted.
// Note: A nullptr pointer will be serialized like an empty string, so when
// deserializing it will result in an allocated buffer only containing a
// single null terminator.
//
// Usage: `JS::UniqueChars s = ...; aEW.WriteObject(s);`
template <>
struct ProfileBufferEntryWriter::Serializer {
  static Length Bytes(const JS::UniqueChars& aS) {
    if (!aS) {
      return ProfileBufferEntryWriter::ULEB128Size(0);
    }
    const auto len = static_cast(strlen(aS.get()));
    return ProfileBufferEntryWriter::ULEB128Size(len) + len;
  }

  static void Write(ProfileBufferEntryWriter& aEW, const JS::UniqueChars& aS) {
    if (!aS) {
      aEW.WriteULEB128(0);
      return;
    }
    const auto len = static_cast(strlen(aS.get()));
    aEW.WriteULEB128(len);
    aEW.WriteBytes(aS.get(), len);
  }
};

template <>
struct ProfileBufferEntryReader::Deserializer {
  static void ReadInto(ProfileBufferEntryReader& aER, JS::UniqueChars& aS) {
    aS = Read(aER);
  }

  static JS::UniqueChars Read(ProfileBufferEntryReader& aER) {
    const auto len = aER.ReadULEB128();
    // Use the same allocation policy as JS_smprintf.
    char* buffer =
        static_cast(js::SystemAllocPolicy{}.pod_malloc(len + 1));
    aER.ReadBytes(buffer, len);
    buffer[len] = '\0';
    return JS::UniqueChars(buffer);
  }
};

}  // namespace mozilla