# Global Metrics

path: .metrics.halstead.N1
old: 216.0
new: 1739.0
path: .metrics.halstead.time
old: 2354.3829372079153
new: 145481.2162417022
path: .metrics.halstead.n2
old: 66.0
new: 176.0
path: .metrics.halstead.estimated_program_length
old: 479.6406346330861
new: 1447.4659026977772
path: .metrics.halstead.vocabulary
old: 85.0
new: 204.0
path: .metrics.halstead.N2
old: 132.0
new: 1377.0
path: .metrics.halstead.effort
old: 42378.89286974248
new: 2618661.8923506397
path: .metrics.halstead.length
old: 348.0
new: 3116.0
path: .metrics.halstead.volume
old: 2230.46804577592
new: 23907.27736558318
path: .metrics.halstead.difficulty
old: 19.0
new: 109.5340909090909
path: .metrics.halstead.level
old: 0.05263157894736842
new: 0.009129577757028738
path: .metrics.halstead.n1
old: 19.0
new: 28.0
path: .metrics.halstead.bugs
old: 0.4051773407776535
new: 6.332837790236661
path: .metrics.halstead.purity_ratio
old: 1.3782776857272587
new: 0.4645269264113534
path: .metrics.nargs.sum
old: 5.0
new: 59.0
path: .metrics.nargs.average
old: 0.8333333333333334
new: 1.5526315789473684
path: .metrics.cyclomatic.average
old: 2.857142857142857
new: 1.1578947368421053
path: .metrics.cyclomatic.sum
old: 20.0
new: 44.0
path: .metrics.loc.blank
old: 26.0
new: 141.0
path: .metrics.loc.cloc
old: 9.0
new: 28.0
path: .metrics.loc.sloc
old: 121.0
new: 656.0
path: .metrics.loc.lloc
old: 42.0
new: 174.0
path: .metrics.loc.ploc
old: 86.0
new: 487.0
path: .metrics.cognitive.average
old: 2.1666666666666665
new: 0.15789473684210523
path: .metrics.cognitive.sum
old: 13.0
new: 6.0
path: .metrics.nexits.sum
old: 17.0
new: 15.0
path: .metrics.nexits.average
old: 2.8333333333333335
new: 0.3947368421052632
path: .metrics.nom.closures
old: 0.0
new: 3.0
path: .metrics.nom.total
old: 6.0
new: 38.0
path: .metrics.nom.functions
old: 6.0
new: 35.0
path: .metrics.mi.mi_visual_studio
old: 28.43062349327495
new: 1.975506820502632
path: .metrics.mi.mi_original
old: 48.61636617350017
new: 3.378116663059501
path: .metrics.mi.mi_sei
old: 16.976562243833712
new: -50.615964284557165

# Spaces Data

## Minimal test - lines (17, 35)

path: .spaces[0].metrics.loc.ploc
old: 1.0
new: 15.0
path: .spaces[0].metrics.loc.sloc
old: 1.0
new: 19.0
path: .spaces[0].metrics.loc.blank
old: 0.0
new: 4.0
path: .spaces[0].metrics.halstead.time
old: 5.2832083357371875
new: 226.9788001619635
path: .spaces[0].metrics.halstead.difficulty
old: 3.0
new: 15.363636363636363
path: .spaces[0].metrics.halstead.length
old: 10.0
new: 58.0
path: .spaces[0].metrics.halstead.n2
old: 3.0
new: 11.0
path: .spaces[0].metrics.halstead.n1
old: 6.0
new: 13.0
path: .spaces[0].metrics.halstead.purity_ratio
old: 2.0264662506490403
new: 1.485508002428353
path: .spaces[0].metrics.halstead.vocabulary
old: 9.0
new: 24.0
path: .spaces[0].metrics.halstead.level
old: 0.3333333333333333
new: 0.0650887573964497
path: .spaces[0].metrics.halstead.estimated_program_length
old: 20.264662506490403
new: 86.15946414084446
path: .spaces[0].metrics.halstead.effort
old: 95.09775004326936
new: 4085.6184029153433
path: .spaces[0].metrics.halstead.N2
old: 3.0
new: 26.0
path: .spaces[0].metrics.halstead.volume
old: 31.69925001442312
new: 265.9278250418271
path: .spaces[0].metrics.halstead.bugs
old: 0.006944786620971931
new: 0.08518908350677537
path: .spaces[0].metrics.halstead.N1
old: 7.0
new: 32.0
path: .spaces[0].metrics.cyclomatic.sum
old: 1.0
new: 3.0
path: .spaces[0].metrics.nargs.sum
old: 0.0
new: 1.0
path: .spaces[0].metrics.nargs.average
old: 0.0
new: 0.5
path: .spaces[0].metrics.mi.mi_sei
old: 144.8408406278255
new: 59.60814144856013
path: .spaces[0].metrics.mi.mi_visual_studio
old: 89.35513233151332
new: 54.72357828206058
path: .spaces[0].metrics.mi.mi_original
old: 152.79727628688778
new: 93.5773188623236
path: .spaces[0].metrics.nexits.average
old: 1.0
new: 0.5
path: .spaces[0].metrics.nom.functions
old: 1.0
new: 2.0
path: .spaces[0].metrics.nom.total
old: 1.0
new: 2.0

### Code

    class InputStreamCallback final : public nsIInputStreamCallback {
      nsCOMPtr mStream;
      nsCOMPtr mCallback;

     public:
      NS_DECL_THREADSAFE_ISUPPORTS

      InputStreamCallback(nsIAsyncInputStream* aStream,
                          nsIInputStreamCallback* aCallback)
          : mStream(aStream), mCallback(aCallback) {}

      NS_IMETHOD
      OnInputStreamReady(nsIAsyncInputStream* aStream) override {
        return mCallback->OnInputStreamReady(mStream);
      }

     private:
      ~InputStreamCallback() = default;
    };

## Minimal test - lines (141, 158)

path: .spaces[4].metrics.loc.sloc
old: 8.0
new: 18.0
path: .spaces[4].metrics.loc.blank
old: 1.0
new: 3.0
path: .spaces[4].metrics.loc.lloc
old: 3.0
new: 5.0
path: .spaces[4].metrics.loc.ploc
old: 7.0
new: 15.0
path: .spaces[4].metrics.nexits.average
old: 2.0
new: 0.0
path: .spaces[4].metrics.nexits.sum
old: 2.0
new: 0.0
path: .spaces[4].metrics.halstead.bugs
old: 0.029027422118425537
new: 0.11776453259389048
path: .spaces[4].metrics.halstead.estimated_program_length
old: 44.82892142331043
new: 152.14764132514549
path: .spaces[4].metrics.halstead.n1
old: 10.0
new: 13.0
path: .spaces[4].metrics.halstead.N1
old: 18.0
new: 56.0
path: .spaces[4].metrics.halstead.purity_ratio
old: 1.7241892855119398
new: 1.506412290347975
path: .spaces[4].metrics.halstead.level
old: 0.125
new: 0.07863247863247863
path: .spaces[4].metrics.halstead.time
old: 45.146291327031776
new: 368.91910472248674
path: .spaces[4].metrics.halstead.effort
old: 812.6332438865719
new: 6640.543885004761
path: .spaces[4].metrics.halstead.n2
old: 5.0
new: 23.0
path: .spaces[4].metrics.halstead.vocabulary
old: 15.0
new: 36.0
path: .spaces[4].metrics.halstead.N2
old: 8.0
new: 45.0
path: .spaces[4].metrics.halstead.volume
old: 101.57915548582147
new: 522.1624251456735
path: .spaces[4].metrics.halstead.difficulty
old: 8.0
new: 12.717391304347826
path: .spaces[4].metrics.halstead.length
old: 26.0
new: 101.0
path: .spaces[4].metrics.nargs.sum
old: 0.0
new: 2.0
path: .spaces[4].metrics.nargs.average
old: 0.0
new: 2.0
path: .spaces[4].metrics.cognitive.sum
old: 1.0
new: 0.0
path: .spaces[4].metrics.cognitive.average
old: 1.0
new: 0.0
path: .spaces[4].metrics.cyclomatic.average
old: 2.0
new: 1.0
path: .spaces[4].metrics.cyclomatic.sum
old: 2.0
new: 1.0
path: .spaces[4].metrics.mi.mi_visual_studio
old: 65.97934947175618
new: 53.45291712777858
path: .spaces[4].metrics.mi.mi_sei
old: 87.27440501240619
new: 56.269769836205995
path: .spaces[4].metrics.mi.mi_original
old: 112.82468759670306
new: 91.40448828850138

### Code

    TEST(TestSlicedInputStream, Simple)
    {
      const size_t kBufSize = 4096;

      nsCString buf;
      RefPtr sis =
          CreateSeekableStreams(kBufSize, 0, kBufSize, buf);

      uint64_t length;
      ASSERT_EQ(NS_OK, sis->Available(&length));
      ASSERT_EQ((uint64_t)kBufSize, length);

      char buf2[kBufSize];
      uint32_t count;
      ASSERT_EQ(NS_OK, sis->Read(buf2, sizeof(buf2), &count));
      ASSERT_EQ(count, buf.Length());
      ASSERT_TRUE(nsCString(buf.get()).Equals(nsCString(buf2)));
    }

## Minimal test - lines (112, 123)

path: .spaces[2].metrics.halstead.n1
old: 7.0
new: 17.0
path: .spaces[2].metrics.halstead.estimated_program_length
old: 43.65148445440323
new: 144.5455183272174
path: .spaces[2].metrics.halstead.N1
old: 11.0
new: 43.0
path: .spaces[2].metrics.halstead.purity_ratio
old: 2.1825742227201617
new: 1.927273577696232
path: .spaces[2].metrics.halstead.vocabulary
old: 15.0
new: 35.0
path: .spaces[2].metrics.halstead.effort
old: 307.6676344041709
new: 5813.187419204295
path: .spaces[2].metrics.halstead.N2
old: 9.0
new: 32.0
path: .spaces[2].metrics.halstead.volume
old: 78.13781191217038
new: 384.6962262708725
path: .spaces[2].metrics.halstead.time
old: 17.09264635578727
new: 322.95485662246085
path: .spaces[2].metrics.halstead.level
old: 0.25396825396825395
new: 0.0661764705882353
path: .spaces[2].metrics.halstead.n2
old: 8.0
new: 18.0
path: .spaces[2].metrics.halstead.difficulty
old: 3.9375
new: 15.11111111111111
path: .spaces[2].metrics.halstead.length
old: 20.0
new: 75.0
path: .spaces[2].metrics.halstead.bugs
old: 0.015191475358116192
new: 0.10776762087110206
path: .spaces[2].metrics.cognitive.sum
old: 0.0
new: 1.0
path: .spaces[2].metrics.cognitive.average
old: 0.0
new: 1.0
path: .spaces[2].metrics.nargs.sum
old: 1.0
new: 0.0
path: .spaces[2].metrics.nargs.average
old: 1.0
new: 0.0
path: .spaces[2].metrics.mi.mi_sei
old: 100.45743031615037
new: 67.80821297904086
path: .spaces[2].metrics.mi.mi_visual_studio
old: 71.36435120802044
new: 58.08874355119145
path: .spaces[2].metrics.mi.mi_original
old: 122.03304056571494
new: 99.33175147253738
path: .spaces[2].metrics.cyclomatic.average
old: 1.0
new: 2.0
path: .spaces[2].metrics.cyclomatic.sum
old: 1.0
new: 2.0
path: .spaces[2].metrics.loc.lloc
old: 3.0
new: 5.0
path: .spaces[2].metrics.loc.blank
old: 0.0
new: 1.0
path: .spaces[2].metrics.loc.ploc
old: 5.0
new: 11.0
path: .spaces[2].metrics.loc.sloc
old: 5.0
new: 12.0

### Code

    static SlicedInputStream* CreateSeekableStreams(uint32_t aSize, uint64_t aStart,
                                                    uint64_t aLength,
                                                    nsCString& aBuffer) {
      aBuffer.SetLength(aSize);
      for (uint32_t i = 0; i < aSize; ++i) {
        aBuffer.BeginWriting()[i] = i % 10;
      }

      nsCOMPtr stream;
      NS_NewCStringInputStream(getter_AddRefs(stream), aBuffer);
      return new SlicedInputStream(stream.forget(), aStart, aLength);
    }

## Minimal test - lines (44, 107)

path: .spaces[1].metrics.cyclomatic.average
old: 1.0
new: 1.181818181818182
path: .spaces[1].metrics.cyclomatic.sum
old: 1.0
new: 13.0
path: .spaces[1].metrics.mi.mi_visual_studio
old: 77.54987902751634
new: 36.81103406471366
path: .spaces[1].metrics.mi.mi_sei
old: 115.71718014704972
new: 16.435940844963895
path: .spaces[1].metrics.mi.mi_original
old: 132.6102931370529
new: 62.94686825066036
path: .spaces[1].metrics.nexits.average
old: 1.0
new: 0.9
path: .spaces[1].metrics.nexits.sum
old: 1.0
new: 9.0
path: .spaces[1].metrics.nargs.average
old: 0.0
new: 1.6
path: .spaces[1].metrics.nargs.sum
old: 0.0
new: 16.0
path: .spaces[1].metrics.halstead.effort
old: 200.75790004038475
new: 29604.80534581721
path: .spaces[1].metrics.halstead.length
old: 14.0
new: 236.0
path: .spaces[1].metrics.halstead.n1
old: 8.0
new: 18.0
path: .spaces[1].metrics.halstead.volume
old: 50.18947501009619
new: 1405.1903292513025
path: .spaces[1].metrics.halstead.difficulty
old: 4.0
new: 21.068181818181817
path: .spaces[1].metrics.halstead.purity_ratio
old: 2.2857142857142856
new: 1.3359052595169605
path: .spaces[1].metrics.halstead.N1
old: 10.0
new: 133.0
path: .spaces[1].metrics.halstead.bugs
old: 0.011428621282029669
new: 0.31899721040412315
path: .spaces[1].metrics.halstead.vocabulary
old: 12.0
new: 62.0
path: .spaces[1].metrics.halstead.time
old: 11.153216668910265
new: 1644.711408100956
path: .spaces[1].metrics.halstead.n2
old: 4.0
new: 44.0
path: .spaces[1].metrics.halstead.estimated_program_length
old: 32.0
new: 315.2736412460027
path: .spaces[1].metrics.halstead.N2
old: 4.0
new: 103.0
path: .spaces[1].metrics.halstead.level
old: 0.25
new: 0.04746494066882417
path: .spaces[1].metrics.loc.blank
old: 0.0
new: 14.0
path: .spaces[1].metrics.loc.lloc
old: 1.0
new: 14.0
path: .spaces[1].metrics.loc.ploc
old: 3.0
new: 50.0
path: .spaces[1].metrics.loc.sloc
old: 3.0
new: 64.0
path: .spaces[1].metrics.cognitive.average
old: 0.0
new: 0.2
path: .spaces[1].metrics.cognitive.sum
old: 0.0
new: 2.0
path: .spaces[1].metrics.nom.total
old: 1.0
new: 10.0
path: .spaces[1].metrics.nom.functions
old: 1.0
new: 10.0

### Code

    class NonSeekableStringStream final : public nsIAsyncInputStream {
      nsCOMPtr mStream;

     public:
      NS_DECL_THREADSAFE_ISUPPORTS

      explicit NonSeekableStringStream(const nsACString& aBuffer) {
        NS_NewCStringInputStream(getter_AddRefs(mStream), aBuffer);
      }

      explicit NonSeekableStringStream(nsIInputStream* aStream)
          : mStream(aStream) {}

      NS_IMETHOD
      Available(uint64_t* aLength) override { return mStream->Available(aLength); }

      NS_IMETHOD
      Read(char* aBuffer, uint32_t aCount, uint32_t* aReadCount) override {
        return mStream->Read(aBuffer, aCount, aReadCount);
      }

      NS_IMETHOD
      ReadSegments(nsWriteSegmentFun aWriter, void* aClosure, uint32_t aCount,
                   uint32_t* aResult) override {
        return mStream->ReadSegments(aWriter, aClosure, aCount, aResult);
      }

      NS_IMETHOD
      Close() override { return mStream->Close(); }

      NS_IMETHOD
      IsNonBlocking(bool* aNonBlocking) override {
        return mStream->IsNonBlocking(aNonBlocking);
      }

      NS_IMETHOD
      CloseWithStatus(nsresult aStatus) override {
        nsCOMPtr async = do_QueryInterface(mStream);
        if (!async) {
          MOZ_CRASH("This should not happen.");
          return NS_ERROR_FAILURE;
        }

        return async->CloseWithStatus(aStatus);
      }

      NS_IMETHOD
      AsyncWait(nsIInputStreamCallback* aCallback, uint32_t aFlags,
                uint32_t aRequestedCount, nsIEventTarget* aEventTarget) override {
        nsCOMPtr async = do_QueryInterface(mStream);
        if (!async) {
          MOZ_CRASH("This should not happen.");
          return NS_ERROR_FAILURE;
        }

        RefPtr callback =
            new InputStreamCallback(this, aCallback);

        return async->AsyncWait(callback, aFlags, aRequestedCount, aEventTarget);
      }

     private:
      ~NonSeekableStringStream() = default;
    };

## Minimal test - lines (161, 177)

path: .spaces[5].metrics.cognitive.sum
old: 12.0
new: 0.0
path: .spaces[5].metrics.cognitive.average
old: 12.0
new: 0.0
path: .spaces[5].metrics.loc.lloc
old: 32.0
new: 5.0
path: .spaces[5].metrics.loc.sloc
old: 68.0
new: 17.0
path: .spaces[5].metrics.loc.blank
old: 11.0
new: 3.0
path: .spaces[5].metrics.loc.ploc
old: 53.0
new: 14.0
path: .spaces[5].metrics.loc.cloc
old: 4.0
new: 0.0
path: .spaces[5].metrics.halstead.n1
old: 17.0
new: 15.0
path: .spaces[5].metrics.halstead.n2
old: 43.0
new: 24.0
path: .spaces[5].metrics.halstead.bugs
old: 0.24245130792033273
new: 0.1395106782504896
path: .spaces[5].metrics.halstead.length
old: 210.0
new: 108.0
path: .spaces[5].metrics.halstead.vocabulary
old: 60.0
new: 39.0
path: .spaces[5].metrics.halstead.effort
old: 19616.371559369687
new: 8562.351594556843
path: .spaces[5].metrics.halstead.N2
old: 80.0
new: 48.0
path: .spaces[5].metrics.halstead.volume
old: 1240.447025077789
new: 570.8234396371229
path: .spaces[5].metrics.halstead.purity_ratio
old: 1.4419821559687902
new: 1.5615042495503288
path: .spaces[5].metrics.halstead.estimated_program_length
old: 302.81625275344595
new: 168.64245895143551
path: .spaces[5].metrics.halstead.level
old: 0.06323529411764706
new: 0.06666666666666667
path: .spaces[5].metrics.halstead.difficulty
old: 15.813953488372093
new: 15.0
path: .spaces[5].metrics.halstead.N1
old: 130.0
new: 60.0
path: .spaces[5].metrics.halstead.time
old: 1089.7984199649827
new: 475.6861996976024
path: .spaces[5].metrics.mi.mi_sei
old: 34.30234892064837
new: 56.937217983477595
path: .spaces[5].metrics.mi.mi_original
old: 62.61319426796102
new: 91.86712808995269
path: .spaces[5].metrics.mi.mi_visual_studio
old: 36.615903080678954
new: 53.72346671927057
path: .spaces[5].metrics.nexits.average
old: 11.0
new: 0.0
path: .spaces[5].metrics.nexits.sum
old: 11.0
new: 0.0
path: .spaces[5].metrics.cyclomatic.sum
old: 13.0
new: 1.0
path: .spaces[5].metrics.cyclomatic.average
old: 13.0
new: 1.0

### Code

    TEST(TestSlicedInputStream, Sliced)
    {
      const size_t kBufSize = 4096;

      nsCString buf;
      RefPtr sis = CreateSeekableStreams(kBufSize, 10, 100, buf);

      uint64_t length;
      ASSERT_EQ(NS_OK, sis->Available(&length));
      ASSERT_EQ((uint64_t)100, length);

      char buf2[kBufSize / 2];
      uint32_t count;
      ASSERT_EQ(NS_OK, sis->Read(buf2, sizeof(buf2), &count));
      ASSERT_EQ((uint64_t)100, count);
      ASSERT_TRUE(nsCString(buf.get() + 10, count).Equals(nsCString(buf2, count)));
    }

## Minimal test - lines (127, 138)

path: .spaces[3].metrics.mi.mi_sei
old: 106.89188477223811
new: 68.23965629082635
path: .spaces[3].metrics.mi.mi_visual_studio
old: 73.97255235695529
new: 58.26362876472102
path: .spaces[3].metrics.mi.mi_original
old: 126.49306453039355
new: 99.63080518767292
path: .spaces[3].metrics.loc.sloc
old: 4.0
new: 12.0
path: .spaces[3].metrics.loc.ploc
old: 4.0
new: 11.0
path: .spaces[3].metrics.loc.lloc
old: 2.0
new: 4.0
path: .spaces[3].metrics.loc.blank
old: 0.0
new: 1.0
path: .spaces[3].metrics.cyclomatic.average
old: 1.0
new: 2.0
path: .spaces[3].metrics.cyclomatic.sum
old: 1.0
new: 2.0
path: .spaces[3].metrics.halstead.level
old: 0.2857142857142857
new: 0.06274509803921569
path: .spaces[3].metrics.halstead.difficulty
old: 3.5
new: 15.9375
path: .spaces[3].metrics.halstead.n1
old: 7.0
new: 17.0
path: .spaces[3].metrics.halstead.vocabulary
old: 15.0
new: 33.0
path: .spaces[3].metrics.halstead.N1
old: 9.0
new: 42.0
path: .spaces[3].metrics.halstead.effort
old: 232.45999043870685
new: 5788.442251963825
path: .spaces[3].metrics.halstead.n2
old: 8.0
new: 16.0
path: .spaces[3].metrics.halstead.purity_ratio
old: 2.567734379670778
new: 1.8539842819618857
path: .spaces[3].metrics.halstead.estimated_program_length
old: 43.65148445440323
new: 133.48686830125575
path: .spaces[3].metrics.halstead.time
old: 12.914443913261492
new: 321.58012510910135
path: .spaces[3].metrics.halstead.volume
old: 66.41714012534482
new: 363.1963765938086
path: .spaces[3].metrics.halstead.length
old: 17.0
new: 72.0
path: .spaces[3].metrics.halstead.N2
old: 8.0
new: 30.0
path: .spaces[3].metrics.halstead.bugs
old: 0.01260213774735643
new: 0.10746157840586544
path: .spaces[3].metrics.nargs.sum
old: 2.0
new: 0.0
path: .spaces[3].metrics.nargs.average
old: 2.0
new: 0.0
path: .spaces[3].metrics.cognitive.sum
old: 0.0
new: 1.0
path: .spaces[3].metrics.cognitive.average
old: 0.0
new: 1.0

### Code

    static SlicedInputStream* CreateNonSeekableStreams(uint32_t aSize,
                                                       uint64_t aStart,
                                                       uint64_t aLength,
                                                       nsCString& aBuffer) {
      aBuffer.SetLength(aSize);
      for (uint32_t i = 0; i < aSize; ++i) {
        aBuffer.BeginWriting()[i] = i % 10;
      }

      RefPtr stream = new NonSeekableStringStream(aBuffer);
      return new SlicedInputStream(stream.forget(), aStart, aLength);
    }