# Global Metrics

path: .metrics.nexits.sum
old: 1.0
new: 7.0
path: .metrics.mi.mi_original
old: 75.70516622931807
new: 45.512626480625045
path: .metrics.mi.mi_visual_studio
old: 44.272027034688925
new: 26.615571041301195
path: .metrics.mi.mi_sei
old: 65.77279863506146
new: 18.791589844624088
path: .metrics.cognitive.sum
old: 0.0
new: 14.0
path: .metrics.cognitive.average
old: 0.0
new: 2.0
path: .metrics.loc.cloc
old: 9.0
new: 17.0
path: .metrics.loc.blank
old: 11.0
new: 17.0
path: .metrics.loc.lloc
old: 1.0
new: 37.0
path: .metrics.loc.sloc
old: 46.0
new: 132.0
path: .metrics.loc.ploc
old: 26.0
new: 98.0
path: .metrics.halstead.difficulty
old: 8.068965517241379
new: 22.533333333333335
path: .metrics.halstead.time
old: 206.54286693665577
new: 3240.4474484172188
path: .metrics.halstead.N2
old: 39.0
new: 169.0
path: .metrics.halstead.volume
old: 460.7494723971552
new: 2588.5231096823936
path: .metrics.halstead.estimated_program_length
old: 183.90099886735345
new: 553.5999636849383
path: .metrics.halstead.N1
old: 47.0
new: 225.0
path: .metrics.halstead.bugs
old: 0.07999580553992665
new: 0.5013377456696639
path: .metrics.halstead.length
old: 86.0
new: 394.0
path: .metrics.halstead.purity_ratio
old: 2.1383837077599237
new: 1.4050760499617725
path: .metrics.halstead.vocabulary
old: 41.0
new: 95.0
path: .metrics.halstead.effort
old: 3717.771604859804
new: 58328.05407150994
path: .metrics.halstead.n2
old: 29.0
new: 75.0
path: .metrics.halstead.n1
old: 12.0
new: 20.0
path: .metrics.halstead.level
old: 0.12393162393162394
new: 0.04437869822485207
path: .metrics.nargs.average
old: 0.0
new: 1.4285714285714286
path: .metrics.nargs.sum
old: 0.0
new: 10.0
path: .metrics.nom.total
old: 1.0
new: 7.0
path: .metrics.nom.functions
old: 1.0
new: 7.0
path: .metrics.cyclomatic.average
old: 1.2
new: 2.4
path: .metrics.cyclomatic.sum
old: 6.0
new: 24.0

# Spaces Data

## Minimal test - lines (21, 131)

path: .spaces[0].spaces[0].metrics.cognitive.average
old: 0.0
new: 2.0
path: .spaces[0].spaces[0].metrics.cognitive.sum
old: 0.0
new: 14.0
path: .spaces[0].spaces[0].metrics.halstead.time
old: 187.19436776055704
new: 3306.3692251412576
path: .spaces[0].spaces[0].metrics.halstead.effort
old: 3369.4986196900268
new: 59514.64605254264
path: .spaces[0].spaces[0].metrics.halstead.n1
old: 12.0
new: 20.0
path: .spaces[0].spaces[0].metrics.halstead.bugs
old: 0.07491847591154338
new: 0.5081141804170053
path: .spaces[0].spaces[0].metrics.halstead.vocabulary
old: 36.0
new: 85.0
path: .spaces[0].spaces[0].metrics.halstead.difficulty
old: 8.25
new: 24.307692307692307
path: .spaces[0].spaces[0].metrics.halstead.level
old: 0.12121212121212122
new: 0.04113924050632912
path: .spaces[0].spaces[0].metrics.halstead.N1
old: 46.0
new: 224.0
path: .spaces[0].spaces[0].metrics.halstead.purity_ratio
old: 1.9374512661514127
new: 1.2510274077083685
path: .spaces[0].spaces[0].metrics.halstead.volume
old: 408.42407511394265
new: 2448.387337604602
path: .spaces[0].spaces[0].metrics.halstead.length
old: 79.0
new: 382.0
path: .spaces[0].spaces[0].metrics.halstead.n2
old: 24.0
new: 65.0
path: .spaces[0].spaces[0].metrics.halstead.N2
old: 33.0
new: 158.0
path: .spaces[0].spaces[0].metrics.halstead.estimated_program_length
old: 153.0586500259616
new: 477.8924697445968
path: .spaces[0].spaces[0].metrics.nargs.average
old: 0.0
new: 1.4285714285714286
path: .spaces[0].spaces[0].metrics.nargs.sum
old: 0.0
new: 10.0
path: .spaces[0].spaces[0].metrics.cyclomatic.sum
old: 4.0
new: 22.0
path: .spaces[0].spaces[0].metrics.cyclomatic.average
old: 1.3333333333333333
new: 2.75
path: .spaces[0].spaces[0].metrics.nom.total
old: 1.0
new: 7.0
path: .spaces[0].spaces[0].metrics.nom.functions
old: 1.0
new: 7.0
path: .spaces[0].spaces[0].metrics.nexits.sum
old: 1.0
new: 7.0
path: .spaces[0].spaces[0].metrics.mi.mi_original
old: 84.26581617538443
new: 49.06904948098064
path: .spaces[0].spaces[0].metrics.mi.mi_sei
old: 60.46262233930203
new: 19.75157722517374
path: .spaces[0].spaces[0].metrics.mi.mi_visual_studio
old: 49.278255073324225
new: 28.695350573672886
path: .spaces[0].spaces[0].metrics.loc.lloc
old: 1.0
new: 37.0
path: .spaces[0].spaces[0].metrics.loc.blank
old: 10.0
new: 16.0
path: .spaces[0].spaces[0].metrics.loc.cloc
old: 1.0
new: 10.0
path: .spaces[0].spaces[0].metrics.loc.sloc
old: 29.0
new: 111.0
path: .spaces[0].spaces[0].metrics.loc.ploc
old: 18.0
new: 85.0

### Code

    namespace widget {

    using namespace mozilla::layers;

    WindowSurfaceProvider::WindowSurfaceProvider()
        : mIsX11Display(false),
          mXDisplay(nullptr),
          mXWindow(0),
          mXVisual(nullptr),
          mXDepth(0),
          mWindowSurface(nullptr)
    #ifdef MOZ_WAYLAND
          ,
          mWidget(nullptr)
    #endif
          ,
          mIsShaped(false) {
    }

    void WindowSurfaceProvider::Initialize(Display* aDisplay, Window aWindow,
                                           Visual* aVisual, int aDepth,
                                           bool aIsShaped) {
      // We should not be initialized
      MOZ_ASSERT(!mXDisplay);

      // This should also be a valid initialization
      MOZ_ASSERT(aDisplay && aWindow != X11None && aVisual);

      mXDisplay = aDisplay;
      mXWindow = aWindow;
      mXVisual = aVisual;
      mXDepth = aDepth;
      mIsShaped = aIsShaped;
      mIsX11Display = true;
    }

    #ifdef MOZ_WAYLAND
    void WindowSurfaceProvider::Initialize(nsWindow* aWidget) {
      mWidget = aWidget;
      mIsX11Display = false;
    }
    #endif

    void WindowSurfaceProvider::CleanupResources() { mWindowSurface = nullptr; }

    UniquePtr WindowSurfaceProvider::CreateWindowSurface() {
    #ifdef MOZ_WAYLAND
      if (!mIsX11Display) {
        LOGDRAW(("Drawing to nsWindow %p will use wl_surface\n", mWidget));
        return MakeUnique(mWidget);
      }
    #endif

      // We should be initialized
      MOZ_ASSERT(mXDisplay);

      // Blit to the window with the following priority:
      // 1. XRender (iff XRender is enabled && we are in-process)
      // 2. MIT-SHM
      // 3. XPutImage
      if (!mIsShaped && gfx::gfxVars::UseXRender()) {
        LOGDRAW(("Drawing to Window 0x%lx will use XRender\n", mXWindow));
        return MakeUnique(mXDisplay, mXWindow, mXVisual,
                                                mXDepth);
      }

    #ifdef MOZ_HAVE_SHMIMAGE
      if (!mIsShaped && nsShmImage::UseShm()) {
        LOGDRAW(("Drawing to Window 0x%lx will use MIT-SHM\n", mXWindow));
        return MakeUnique(mXDisplay, mXWindow, mXVisual,
                                               mXDepth);
      }
    #endif  // MOZ_HAVE_SHMIMAGE

      LOGDRAW(("Drawing to Window 0x%lx will use XPutImage\n", mXWindow));
      return MakeUnique(mXDisplay, mXWindow, mXVisual,
                                               mXDepth, mIsShaped);
    }

    already_AddRefed
    WindowSurfaceProvider::StartRemoteDrawingInRegion(
        const LayoutDeviceIntRegion& aInvalidRegion,
        layers::BufferMode* aBufferMode) {
      if (aInvalidRegion.IsEmpty()) return nullptr;

      if (!mWindowSurface) {
        mWindowSurface = CreateWindowSurface();
        if (!mWindowSurface) return nullptr;
      }

      *aBufferMode = BufferMode::BUFFER_NONE;
      RefPtr dt = nullptr;
      if (!(dt = mWindowSurface->Lock(aInvalidRegion)) && mIsX11Display &&
          !mWindowSurface->IsFallback()) {
        // We can't use WindowSurfaceX11Image fallback on Wayland but
        // Lock() call on WindowSurfaceWayland should never fail.
        gfxWarningOnce()
            << "Failed to lock WindowSurface, falling back to XPutImage backend.";
        mWindowSurface = MakeUnique(
            mXDisplay, mXWindow, mXVisual, mXDepth, mIsShaped);
        dt = mWindowSurface->Lock(aInvalidRegion);
      }
      return dt.forget();
    }

    void WindowSurfaceProvider::EndRemoteDrawingInRegion(
        gfx::DrawTarget* aDrawTarget, const LayoutDeviceIntRegion& aInvalidRegion) {
      if (mWindowSurface) mWindowSurface->Commit(aInvalidRegion);
    }

    }  // namespace widget

## Minimal test - lines (20, 132)

path: .spaces[0].metrics.nexits.sum
old: 1.0
new: 7.0
path: .spaces[0].metrics.mi.mi_original
old: 82.78580204685679
new: 48.50893006937622
path: .spaces[0].metrics.mi.mi_visual_studio
old: 48.41274973500397
new: 28.367795362208316
path: .spaces[0].metrics.mi.mi_sei
old: 63.41386871645268
new: 19.8620484126619
path: .spaces[0].metrics.nargs.sum
old: 0.0
new: 10.0
path: .spaces[0].metrics.nargs.average
old: 0.0
new: 1.4285714285714286
path: .spaces[0].metrics.nom.functions
old: 1.0
new: 7.0
path: .spaces[0].metrics.nom.total
old: 1.0
new: 7.0
path: .spaces[0].metrics.cyclomatic.average
old: 1.25
new: 2.5555555555555554
path: .spaces[0].metrics.cyclomatic.sum
old: 5.0
new: 23.0
path: .spaces[0].metrics.cognitive.average
old: 0.0
new: 2.0
path: .spaces[0].metrics.cognitive.sum
old: 0.0
new: 14.0
path: .spaces[0].metrics.loc.lloc
old: 1.0
new: 37.0
path: .spaces[0].metrics.loc.blank
old: 9.0
new: 15.0
path: .spaces[0].metrics.loc.ploc
old: 20.0
new: 87.0
path: .spaces[0].metrics.loc.cloc
old: 2.0
new: 11.0
path: .spaces[0].metrics.loc.sloc
old: 31.0
new: 113.0
path: .spaces[0].metrics.halstead.difficulty
old: 8.16
new: 24.09090909090909
path: .spaces[0].metrics.halstead.purity_ratio
old: 1.964394503123728
new: 1.263980660873451
path: .spaces[0].metrics.halstead.vocabulary
old: 37.0
new: 86.0
path: .spaces[0].metrics.halstead.estimated_program_length
old: 159.11595475302198
new: 485.3685737754052
path: .spaces[0].metrics.halstead.level
old: 0.12254901960784312
new: 0.04150943396226416
path: .spaces[0].metrics.halstead.n2
old: 25.0
new: 66.0
path: .spaces[0].metrics.halstead.n1
old: 12.0
new: 20.0
path: .spaces[0].metrics.halstead.time
old: 191.29112758589503
new: 3302.7106133256843
path: .spaces[0].metrics.halstead.N2
old: 34.0
new: 159.0
path: .spaces[0].metrics.halstead.volume
old: 421.96572261594497
new: 2467.685665805606
path: .spaces[0].metrics.halstead.effort
old: 3443.240296546111
new: 59448.79103986232
path: .spaces[0].metrics.halstead.N1
old: 47.0
new: 225.0
path: .spaces[0].metrics.halstead.bugs
old: 0.07600759076519305
new: 0.5077392806551302
path: .spaces[0].metrics.halstead.length
old: 81.0
new: 384.0

### Code

    namespace mozilla {
    namespace widget {

    using namespace mozilla::layers;

    WindowSurfaceProvider::WindowSurfaceProvider()
        : mIsX11Display(false),
          mXDisplay(nullptr),
          mXWindow(0),
          mXVisual(nullptr),
          mXDepth(0),
          mWindowSurface(nullptr)
    #ifdef MOZ_WAYLAND
          ,
          mWidget(nullptr)
    #endif
          ,
          mIsShaped(false) {
    }

    void WindowSurfaceProvider::Initialize(Display* aDisplay, Window aWindow,
                                           Visual* aVisual, int aDepth,
                                           bool aIsShaped) {
      // We should not be initialized
      MOZ_ASSERT(!mXDisplay);

      // This should also be a valid initialization
      MOZ_ASSERT(aDisplay && aWindow != X11None && aVisual);

      mXDisplay = aDisplay;
      mXWindow = aWindow;
      mXVisual = aVisual;
      mXDepth = aDepth;
      mIsShaped = aIsShaped;
      mIsX11Display = true;
    }

    #ifdef MOZ_WAYLAND
    void WindowSurfaceProvider::Initialize(nsWindow* aWidget) {
      mWidget = aWidget;
      mIsX11Display = false;
    }
    #endif

    void WindowSurfaceProvider::CleanupResources() { mWindowSurface = nullptr; }

    UniquePtr WindowSurfaceProvider::CreateWindowSurface() {
    #ifdef MOZ_WAYLAND
      if (!mIsX11Display) {
        LOGDRAW(("Drawing to nsWindow %p will use wl_surface\n", mWidget));
        return MakeUnique(mWidget);
      }
    #endif

      // We should be initialized
      MOZ_ASSERT(mXDisplay);

      // Blit to the window with the following priority:
      // 1. XRender (iff XRender is enabled && we are in-process)
      // 2. MIT-SHM
      // 3. XPutImage
      if (!mIsShaped && gfx::gfxVars::UseXRender()) {
        LOGDRAW(("Drawing to Window 0x%lx will use XRender\n", mXWindow));
        return MakeUnique(mXDisplay, mXWindow, mXVisual,
                                                mXDepth);
      }

    #ifdef MOZ_HAVE_SHMIMAGE
      if (!mIsShaped && nsShmImage::UseShm()) {
        LOGDRAW(("Drawing to Window 0x%lx will use MIT-SHM\n", mXWindow));
        return MakeUnique(mXDisplay, mXWindow, mXVisual,
                                               mXDepth);
      }
    #endif  // MOZ_HAVE_SHMIMAGE

      LOGDRAW(("Drawing to Window 0x%lx will use XPutImage\n", mXWindow));
      return MakeUnique(mXDisplay, mXWindow, mXVisual,
                                               mXDepth, mIsShaped);
    }

    already_AddRefed
    WindowSurfaceProvider::StartRemoteDrawingInRegion(
        const LayoutDeviceIntRegion& aInvalidRegion,
        layers::BufferMode* aBufferMode) {
      if (aInvalidRegion.IsEmpty()) return nullptr;

      if (!mWindowSurface) {
        mWindowSurface = CreateWindowSurface();
        if (!mWindowSurface) return nullptr;
      }

      *aBufferMode = BufferMode::BUFFER_NONE;
      RefPtr dt = nullptr;
      if (!(dt = mWindowSurface->Lock(aInvalidRegion)) && mIsX11Display &&
          !mWindowSurface->IsFallback()) {
        // We can't use WindowSurfaceX11Image fallback on Wayland but
        // Lock() call on WindowSurfaceWayland should never fail.
        gfxWarningOnce()
            << "Failed to lock WindowSurface, falling back to XPutImage backend.";
        mWindowSurface = MakeUnique(
            mXDisplay, mXWindow, mXVisual, mXDepth, mIsShaped);
        dt = mWindowSurface->Lock(aInvalidRegion);
      }
      return dt.forget();
    }

    void WindowSurfaceProvider::EndRemoteDrawingInRegion(
        gfx::DrawTarget* aDrawTarget, const LayoutDeviceIntRegion& aInvalidRegion) {
      if (mWindowSurface) mWindowSurface->Commit(aInvalidRegion);
    }

    }  // namespace widget
    }  // namespace mozilla

## Minimal test - lines (25, 38)

path: .spaces[0].spaces[0].spaces[0].metrics.mi.mi_sei
old: 65.57001885232592
new: 71.28958129324434
path: .spaces[0].spaces[0].spaces[0].metrics.mi.mi_visual_studio
old: 50.960570559729845
new: 59.54118611256694
path: .spaces[0].spaces[0].spaces[0].metrics.mi.mi_original
old: 87.14257565713804
new: 101.81542825248948
path: .spaces[0].spaces[0].spaces[0].metrics.cyclomatic.sum
old: 3.0
new: 1.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.halstead.estimated_program_length
old: 147.06147499796518
new: 59.71535681027101
path: .spaces[0].spaces[0].spaces[0].metrics.halstead.N1
old: 44.0
new: 19.0
path: .spaces[0].spaces[0].spaces[0].metrics.halstead.N2
old: 32.0
new: 18.0
path: .spaces[0].spaces[0].spaces[0].metrics.halstead.bugs
old: 0.07319945434815657
new: 0.021942098735436923
path: .spaces[0].spaces[0].spaces[0].metrics.halstead.level
old: 0.11979166666666669
new: 0.28888888888888886
path: .spaces[0].spaces[0].spaces[0].metrics.halstead.time
old: 180.788641988553
new: 29.6706202025703
path: .spaces[0].spaces[0].spaces[0].metrics.halstead.effort
old: 3254.195555793954
new: 534.0711636462654
path: .spaces[0].spaces[0].spaces[0].metrics.halstead.n1
old: 12.0
new: 5.0
path: .spaces[0].spaces[0].spaces[0].metrics.halstead.n2
old: 23.0
new: 13.0
path: .spaces[0].spaces[0].spaces[0].metrics.halstead.volume
old: 389.82550928781745
new: 154.28722505336555
path: .spaces[0].spaces[0].spaces[0].metrics.halstead.purity_ratio
old: 1.9350194078679628
new: 1.6139285624397568
path: .spaces[0].spaces[0].spaces[0].metrics.halstead.vocabulary
old: 35.0
new: 18.0
path: .spaces[0].spaces[0].spaces[0].metrics.halstead.length
old: 76.0
new: 37.0
path: .spaces[0].spaces[0].spaces[0].metrics.halstead.difficulty
old: 8.347826086956522
new: 3.4615384615384617
path: .spaces[0].spaces[0].spaces[0].metrics.loc.sloc
old: 25.0
new: 14.0
path: .spaces[0].spaces[0].spaces[0].metrics.loc.cloc
old: 1.0
new: 0.0
path: .spaces[0].spaces[0].spaces[0].metrics.loc.lloc
old: 1.0
new: 0.0
path: .spaces[0].spaces[0].spaces[0].metrics.loc.ploc
old: 16.0
new: 14.0
path: .spaces[0].spaces[0].spaces[0].metrics.loc.blank
old: 8.0
new: 0.0
path: .spaces[0].spaces[0].spaces[0].metrics.nexits.sum
old: 1.0
new: 0.0
path: .spaces[0].spaces[0].spaces[0].metrics.nexits.average
old: 1.0
new: 0.0

### Code

    WindowSurfaceProvider::WindowSurfaceProvider()
        : mIsX11Display(false),
          mXDisplay(nullptr),
          mXWindow(0),
          mXVisual(nullptr),
          mXDepth(0),
          mWindowSurface(nullptr)
    #ifdef MOZ_WAYLAND
          ,
          mWidget(nullptr)
    #endif
          ,
          mIsShaped(false) {
    }