From: L. David Baron Bug 572200, part 1: Make rule nodes know whether they're used directly by a style context. diff --git a/layout/style/nsRuleNode.h b/layout/style/nsRuleNode.h --- a/layout/style/nsRuleNode.h +++ b/layout/style/nsRuleNode.h @@ -640,16 +640,28 @@ public: return (mDependentBits & NS_RULE_NODE_LEVEL_MASK) >> NS_RULE_NODE_LEVEL_SHIFT; } bool IsImportantRule() const { NS_ASSERTION(!IsRoot(), "can't call on root"); return (mDependentBits & NS_RULE_NODE_IS_IMPORTANT) != 0; } + /** + * Has this rule node at some time in its lifetime been the mRuleNode + * of some style context (as opposed to only being the ancestor of + * some style context's mRuleNode)? + */ + void SetUsedDirectly() { + mDependentBits |= NS_RULE_NODE_USED_DIRECTLY; + } + bool IsUsedDirectly() const { + return (mDependentBits & NS_RULE_NODE_USED_DIRECTLY) != 0; + } + // NOTE: Does not |AddRef|. nsIStyleRule* GetRule() const { return mRule; } // NOTE: Does not |AddRef|. nsPresContext* GetPresContext() const { return mPresContext; } const void* GetStyleData(nsStyleStructID aSID, nsStyleContext* aContext, bool aComputeData); diff --git a/layout/style/nsStyleContext.cpp b/layout/style/nsStyleContext.cpp --- a/layout/style/nsStyleContext.cpp +++ b/layout/style/nsStyleContext.cpp @@ -60,24 +60,25 @@ nsStyleContext::nsStyleContext(nsStyleCo while (r1->GetParent()) r1 = r1->GetParent(); while (r2->GetParent()) r2 = r2->GetParent(); NS_ASSERTION(r1 == r2, "must be in the same rule tree as parent"); #endif } + mRuleNode->AddRef(); + mRuleNode->SetUsedDirectly(); // before ApplyStyleFixups()! + ApplyStyleFixups(); #define eStyleStruct_LastItem (nsStyleStructID_Length - 1) NS_ASSERTION(NS_STYLE_INHERIT_MASK & NS_STYLE_INHERIT_BIT(LastItem), "NS_STYLE_INHERIT_MASK must be bigger, and other bits shifted"); #undef eStyleStruct_LastItem - - mRuleNode->AddRef(); } nsStyleContext::~nsStyleContext() { NS_ASSERTION((nullptr == mChild) && (nullptr == mEmptyChild), "destructing context with children"); nsPresContext *presContext = mRuleNode->GetPresContext(); diff --git a/layout/style/nsStyleStruct.h b/layout/style/nsStyleStruct.h --- a/layout/style/nsStyleStruct.h +++ b/layout/style/nsStyleStruct.h @@ -55,16 +55,17 @@ struct nsCSSValueList; // See nsStyleContext::IsStyleIfVisited #define NS_STYLE_IS_STYLE_IF_VISITED 0x04000000 // See nsStyleContext::GetPseudoEnum #define NS_STYLE_CONTEXT_TYPE_MASK 0xf8000000 #define NS_STYLE_CONTEXT_TYPE_SHIFT 27 // Additional bits for nsRuleNode's mDependentBits: #define NS_RULE_NODE_GC_MARK 0x02000000 +#define NS_RULE_NODE_USED_DIRECTLY 0x04000000 #define NS_RULE_NODE_IS_IMPORTANT 0x08000000 #define NS_RULE_NODE_LEVEL_MASK 0xf0000000 #define NS_RULE_NODE_LEVEL_SHIFT 28 // The lifetime of these objects is managed by the presshell's arena. struct nsStyleFont { nsStyleFont(const nsFont& aFont, nsPresContext *aPresContext);