From a922ec08238cc9b7334c33c0b8114ad038bb6652 Mon Sep 17 00:00:00 2001 From: Francis Dominic Fajardo Date: Tue, 22 Jul 2025 12:57:08 +0800 Subject: [PATCH] =?UTF-8?q?Issue=20#2828=20=E2=80=93=20Part=2010:=20Clean?= =?UTF-8?q?=20up=20cascade=20layer=20constructor?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This also renames mIsWeak to mIsStrong. Cascade layers are weak by default and there's no point in always setting this to true. --- layout/style/RuleCascadeData.cpp | 55 +++++------------------------ layout/style/RuleCascadeData.h | 15 +------- layout/style/nsCSSRuleProcessor.cpp | 3 ++ 3 files changed, 13 insertions(+), 60 deletions(-) diff --git a/layout/style/RuleCascadeData.cpp b/layout/style/RuleCascadeData.cpp index 4cac848d46..b834271e29 100644 --- a/layout/style/RuleCascadeData.cpp +++ b/layout/style/RuleCascadeData.cpp @@ -1545,24 +1545,20 @@ InitWeightEntry(PLDHashEntryHdr* hdr, const void* key) }; CascadeLayer::CascadeLayer(nsPresContext* aPresContext, - nsString aName, #ifdef DEBUG CascadeLayer* aParent, #endif - bool aIsWeak, nsTArray& aDocumentRules, nsDocumentRuleResultCacheKey& aDocumentKey, SheetType aSheetType, bool aMustGatherDocumentRules, nsMediaQueryResultCacheKey& aCacheKey) : mPresContext(aPresContext) - , mName(aName) - , mIsAnonymous(mName.IsEmpty()) - , mIsWeak(aIsWeak) + , mIsAnonymous(true) + , mIsStrong(false) , mRulesAdded(false) #ifdef DEBUG , mParent(aParent) - , mIsRoot(false) #endif , mDocumentRules(aDocumentRules) , mDocumentCacheKey(aDocumentKey) @@ -1571,31 +1567,12 @@ CascadeLayer::CascadeLayer(nsPresContext* aPresContext, , mRulesByWeight(&sRulesByWeightOps, sizeof(RuleByWeightEntry), 32) , mCacheKey(aCacheKey) { - Initialize(); -} + mData = new RuleCascadeData(eCompatibility_NavQuirks == + mPresContext->CompatibilityMode()); -CascadeLayer::CascadeLayer(nsPresContext* aPresContext, - nsTArray& aDocumentRules, - nsDocumentRuleResultCacheKey& aDocumentKey, - SheetType aSheetType, - bool aMustGatherDocumentRules, - nsMediaQueryResultCacheKey& aCacheKey) - : mPresContext(aPresContext) - , mIsAnonymous(false) - , mIsWeak(false) - , mRulesAdded(false) -#ifdef DEBUG - , mParent(nullptr) - , mIsRoot(true) -#endif - , mDocumentRules(aDocumentRules) - , mDocumentCacheKey(aDocumentKey) - , mSheetType(aSheetType) - , mMustGatherDocumentRules(aMustGatherDocumentRules) - , mRulesByWeight(&sRulesByWeightOps, sizeof(RuleByWeightEntry), 32) - , mCacheKey(aCacheKey) -{ - Initialize(); + // Initialize our arena + PL_INIT_ARENA_POOL( + &mArena, "CascadeLayerArena", NS_CASCADELAYER_ARENA_BLOCK_SIZE); } CascadeLayer::~CascadeLayer() @@ -1617,16 +1594,16 @@ CascadeLayer::CreateNamedChildLayer(const nsTArray& aPath) // Create new layer if it doesn't exist. if (!mLayers.Get(name, &childLayer)) { childLayer = new CascadeLayer(mPresContext, - name, #ifdef DEBUG this, #endif - false, mDocumentRules, mDocumentCacheKey, mSheetType, mMustGatherDocumentRules, mCacheKey); + childLayer->mName = name; + childLayer->mIsAnonymous = false; mPreLayers.AppendElement(childLayer); mLayers.Put(name, childLayer); } @@ -1645,13 +1622,10 @@ CascadeLayer::CreateNamedChildLayer(const nsTArray& aPath) CascadeLayer* CascadeLayer::CreateAnonymousChildLayer() { - nsString name; CascadeLayer* childLayer = new CascadeLayer(mPresContext, - name, #ifdef DEBUG this, #endif - false, mDocumentRules, mDocumentCacheKey, mSheetType, @@ -1762,14 +1736,3 @@ CascadeLayer::EnumerateAllLayers(nsLayerEnumFunc aFunc, void* aData) } } } - -void -CascadeLayer::Initialize() -{ - mData = new RuleCascadeData(eCompatibility_NavQuirks == - mPresContext->CompatibilityMode()); - - // Initialize our arena - PL_INIT_ARENA_POOL( - &mArena, "CascadeLayerArena", NS_CASCADELAYER_ARENA_BLOCK_SIZE); -} diff --git a/layout/style/RuleCascadeData.h b/layout/style/RuleCascadeData.h index e7cddfb8d2..952aed27f3 100644 --- a/layout/style/RuleCascadeData.h +++ b/layout/style/RuleCascadeData.h @@ -325,30 +325,20 @@ private: struct CascadeLayer { CascadeLayer(nsPresContext* aPresContext, - nsString aName, #ifdef DEBUG CascadeLayer* aParent, #endif - bool aIsWeak, nsTArray& aDocumentRules, nsDocumentRuleResultCacheKey& aDocumentKey, SheetType aSheetType, bool aMustGatherDocumentRules, nsMediaQueryResultCacheKey& aCacheKey); - - CascadeLayer(nsPresContext* aPresContext, - nsTArray& aDocumentRules, - nsDocumentRuleResultCacheKey& aDocumentKey, - SheetType aSheetType, - bool aMustGatherDocumentRules, - nsMediaQueryResultCacheKey& aCacheKey); - ~CascadeLayer(); nsPresContext* mPresContext; nsString mName; bool mIsAnonymous; - bool mIsWeak; + bool mIsStrong; bool mRulesAdded; RuleCascadeData* mData; @@ -367,7 +357,6 @@ struct CascadeLayer #ifdef DEBUG CascadeLayer* mParent; - bool mIsRoot; #endif nsTArray mPreLayers; nsTArray mPostLayers; @@ -381,8 +370,6 @@ struct CascadeLayer void AddRules(); private: - void Initialize(); - static const PLDHashTableOps sRulesByWeightOps; }; diff --git a/layout/style/nsCSSRuleProcessor.cpp b/layout/style/nsCSSRuleProcessor.cpp index 958fe1c27a..ebae46cd70 100644 --- a/layout/style/nsCSSRuleProcessor.cpp +++ b/layout/style/nsCSSRuleProcessor.cpp @@ -736,6 +736,9 @@ nsCSSRuleProcessor::RefreshGroup(nsPresContext* aPresContext) nsAutoPtr ruleProcessorSet( new RuleProcessorGroup(aPresContext->Medium())); CascadeLayer* implicitLayer(new CascadeLayer(aPresContext, +#if DEBUG + nullptr, +#endif mDocumentRules, mDocumentCacheKey, mSheetType,