Skip to content

Commit

Permalink
Bug 1733727 part 3: Use StaticAutoPtr to manage lifetime of various "…
Browse files Browse the repository at this point in the history
…gFoo" static global variables in layout. r=jfkthame

This patch doesn't change any user-observable behavior.

StaticAutoPtr lets us remove a handful of explicit 'delete' statements, by
making deletion happen automatically when these variables are cleared.

Differential Revision: https://phabricator.services.mozilla.com/D127337
  • Loading branch information
dholbert committed Oct 2, 2021
1 parent b5c0f07 commit f913735
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 33 deletions.
10 changes: 5 additions & 5 deletions layout/generic/nsGfxScrollFrame.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@
#include "mozilla/ScrollbarPreferences.h"
#include "mozilla/ScrollingMetrics.h"
#include "mozilla/StaticPrefs_browser.h"
#include "mozilla/StaticPtr.h"
#include "mozilla/SVGOuterSVGFrame.h"
#include "mozilla/ViewportUtils.h"
#include "mozilla/LookAndFeel.h"
Expand Down Expand Up @@ -2178,7 +2179,7 @@ class ScrollFrameActivityTracker final
}
};

static ScrollFrameActivityTracker* gScrollFrameActivityTracker = nullptr;
static StaticAutoPtr<ScrollFrameActivityTracker> gScrollFrameActivityTracker;

ScrollFrameHelper::ScrollFrameHelper(nsContainerFrame* aOuter, bool aIsRoot)
: mHScrollbarBox(nullptr),
Expand Down Expand Up @@ -4325,9 +4326,9 @@ nsRect ScrollFrameHelper::RestrictToRootDisplayPort(
}

/* static */ bool ScrollFrameHelper::ShouldActivateAllScrollFrames() {
return (StaticPrefs::apz_wr_activate_all_scroll_frames() ||
(StaticPrefs::apz_wr_activate_all_scroll_frames_when_fission() &&
FissionAutostart()));
return (StaticPrefs::apz_wr_activate_all_scroll_frames() ||
(StaticPrefs::apz_wr_activate_all_scroll_frames_when_fission() &&
FissionAutostart()));
}

bool ScrollFrameHelper::DecideScrollableLayer(
Expand Down Expand Up @@ -5563,7 +5564,6 @@ void ScrollFrameHelper::Destroy(PostDestroyData& aPostDestroyData) {
gScrollFrameActivityTracker->RemoveObject(this);
}
if (gScrollFrameActivityTracker && gScrollFrameActivityTracker->IsEmpty()) {
delete gScrollFrameActivityTracker;
gScrollFrameActivityTracker = nullptr;
}

Expand Down
8 changes: 3 additions & 5 deletions layout/painting/ActiveLayerTracker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
#include "mozilla/EffectSet.h"
#include "mozilla/MotionPathUtils.h"
#include "mozilla/PodOperations.h"
#include "mozilla/StaticPtr.h"
#include "gfx2DGlue.h"
#include "nsExpirationTracker.h"
#include "nsContainerFrame.h"
Expand Down Expand Up @@ -163,7 +164,7 @@ class LayerActivityTracker final
bool mDestroying;
};

static LayerActivityTracker* gLayerActivityTracker = nullptr;
static StaticAutoPtr<LayerActivityTracker> gLayerActivityTracker;

LayerActivity::~LayerActivity() {
if (mFrame || mContent) {
Expand Down Expand Up @@ -606,9 +607,6 @@ void ActiveLayerTracker::SetCurrentScrollHandlerFrame(nsIFrame* aFrame) {
}

/* static */
void ActiveLayerTracker::Shutdown() {
delete gLayerActivityTracker;
gLayerActivityTracker = nullptr;
}
void ActiveLayerTracker::Shutdown() { gLayerActivityTracker = nullptr; }

} // namespace mozilla
8 changes: 3 additions & 5 deletions layout/painting/DisplayItemClip.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
#include "mozilla/gfx/2D.h"
#include "mozilla/gfx/PathHelpers.h"
#include "mozilla/layers/StackingContextHelper.h"
#include "mozilla/StaticPtr.h"
#include "mozilla/webrender/WebRenderTypes.h"
#include "nsPresContext.h"
#include "nsCSSRendering.h"
Expand Down Expand Up @@ -446,7 +447,7 @@ void DisplayItemClip::MoveBy(const nsPoint& aPoint) {
}
}

static DisplayItemClip* gNoClip;
static StaticAutoPtr<DisplayItemClip> gNoClip;

const DisplayItemClip& DisplayItemClip::NoClip() {
if (!gNoClip) {
Expand All @@ -455,10 +456,7 @@ const DisplayItemClip& DisplayItemClip::NoClip() {
return *gNoClip;
}

void DisplayItemClip::Shutdown() {
delete gNoClip;
gNoClip = nullptr;
}
void DisplayItemClip::Shutdown() { gNoClip = nullptr; }

nsCString DisplayItemClip::ToString() const {
nsAutoCString str;
Expand Down
9 changes: 4 additions & 5 deletions layout/painting/HitTestInfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,16 @@
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */

#include "HitTestInfo.h"

#include "mozilla/StaticPtr.h"
#include "mozilla/webrender/WebRenderAPI.h"
#include "nsDisplayList.h"
#include "nsIFrame.h"
#include "mozilla/layers/ScrollableLayerGuid.h"

namespace mozilla {

static const HitTestInfo* gEmptyHitTestInfo = nullptr;
static StaticAutoPtr<const HitTestInfo> gEmptyHitTestInfo;

const HitTestInfo& HitTestInfo::Empty() {
if (gEmptyHitTestInfo) {
Expand All @@ -22,10 +24,7 @@ const HitTestInfo& HitTestInfo::Empty() {
return *gEmptyHitTestInfo;
}

void HitTestInfo::Shutdown() {
delete gEmptyHitTestInfo;
gEmptyHitTestInfo = nullptr;
}
void HitTestInfo::Shutdown() { gEmptyHitTestInfo = nullptr; }

using ViewID = layers::ScrollableLayerGuid::ViewID;

Expand Down
8 changes: 3 additions & 5 deletions layout/painting/nsCSSRendering.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
#include "mozilla/HashFunctions.h"
#include "mozilla/MathAlgorithms.h"
#include "mozilla/PresShell.h"
#include "mozilla/StaticPtr.h"
#include "mozilla/SVGImageContext.h"
#include "gfxFont.h"
#include "ScaledFontBase.h"
Expand Down Expand Up @@ -426,7 +427,7 @@ struct InlineBackgroundData {
}
};

static InlineBackgroundData* gInlineBGData = nullptr;
static StaticAutoPtr<InlineBackgroundData> gInlineBGData;

// Initialize any static variables used by nsCSSRendering.
void nsCSSRendering::Init() {
Expand All @@ -435,10 +436,7 @@ void nsCSSRendering::Init() {
}

// Clean up any global variables used by nsCSSRendering.
void nsCSSRendering::Shutdown() {
delete gInlineBGData;
gInlineBGData = nullptr;
}
void nsCSSRendering::Shutdown() { gInlineBGData = nullptr; }

/**
* Make a bevel color
Expand Down
13 changes: 5 additions & 8 deletions layout/style/nsCSSProps.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,15 @@

#include "mozilla/Preferences.h"
#include "mozilla/StaticPrefs_layout.h"
#include "mozilla/StaticPtr.h"

using namespace mozilla;

static int32_t gPropertyTableRefCount;
static nsStaticCaseInsensitiveNameTable* gFontDescTable;
static nsStaticCaseInsensitiveNameTable* gCounterDescTable;
static nsTHashMap<nsCStringHashKey, nsCSSPropertyID>* gPropertyIDLNameTable;
static StaticAutoPtr<nsStaticCaseInsensitiveNameTable> gFontDescTable;
static StaticAutoPtr<nsStaticCaseInsensitiveNameTable> gCounterDescTable;
static StaticAutoPtr<nsTHashMap<nsCStringHashKey, nsCSSPropertyID>>
gPropertyIDLNameTable;

static const char* const kCSSRawFontDescs[] = {
#define CSS_FONT_DESC(name_, method_) #name_,
Expand Down Expand Up @@ -121,13 +123,8 @@ void nsCSSProps::AddRefTable(void) {

void nsCSSProps::ReleaseTable(void) {
if (0 == --gPropertyTableRefCount) {
delete gFontDescTable;
gFontDescTable = nullptr;

delete gCounterDescTable;
gCounterDescTable = nullptr;

delete gPropertyIDLNameTable;
gPropertyIDLNameTable = nullptr;
}
}
Expand Down

0 comments on commit f913735

Please sign in to comment.