Bug 1188721 - Part 8: Remove the ability to swap structs between style contexts. r?dbaron
MozReview-Commit-ID: 2bx8yg1Av5r
--- a/layout/style/nsRuleNode.h
+++ b/layout/style/nsRuleNode.h
@@ -45,19 +45,16 @@ public:
}
}
bool ClearStyleData(nsStyleStructID aSID) {
bool shouldDelete = mStyleStructs[aSID] &&
mStyleStructs[aSID]->ReleaseWithoutDestroying() == 0;
mStyleStructs[aSID] = nullptr;
return shouldDelete;
}
- void SwapStyleData(nsStyleStructID aSID, nsInheritedStyleData& aOther) {
- std::swap(mStyleStructs[aSID], aOther.mStyleStructs[aSID]);
- }
bool ReplaceStyleData(nsStyleStructID aSID, nsStyleStruct* aStyleStruct) {
MOZ_ASSERT(aStyleStruct);
nsStyleStruct* old = mStyleStructs[aSID];
aStyleStruct->AddRef();
mStyleStructs[aSID] = aStyleStruct;
return old && old->ReleaseWithoutDestroying() == 0;
}
@@ -115,19 +112,16 @@ public:
}
}
bool ClearStyleData(nsStyleStructID aSID) {
bool shouldDelete = mStyleStructs[aSID] &&
mStyleStructs[aSID]->ReleaseWithoutDestroying() == 0;
mStyleStructs[aSID] = nullptr;
return shouldDelete;
}
- void SwapStyleData(nsStyleStructID aSID, nsResetStyleData& aOther) {
- std::swap(mStyleStructs[aSID], aOther.mStyleStructs[aSID]);
- }
bool ReplaceStyleData(nsStyleStructID aSID, nsStyleStruct* aStyleStruct) {
MOZ_ASSERT(aStyleStruct);
nsStyleStruct* old = mStyleStructs[aSID];
aStyleStruct->AddRef();
mStyleStructs[aSID] = aStyleStruct;
return old && old->ReleaseWithoutDestroying() == 0;
}
--- a/layout/style/nsStyleContext.cpp
+++ b/layout/style/nsStyleContext.cpp
@@ -1391,69 +1391,16 @@ nsStyleContext::LookupStruct(const nsACS
#undef STYLE_STRUCT
else
return false;
return true;
}
#endif
void
-nsStyleContext::SwapStyleData(nsStyleContext* aNewContext, uint32_t aStructs)
-{
- static_assert(nsStyleStructID_Length <= 32, "aStructs is not big enough");
-
- for (nsStyleStructID i = nsStyleStructID_Inherited_Start;
- i < nsStyleStructID_Inherited_Start + nsStyleStructID_Inherited_Count;
- i = nsStyleStructID(i + 1)) {
- uint32_t bit = nsCachedStyleData::GetBitForSID(i);
- if (!(aStructs & bit)) {
- continue;
- }
- nsStyleStruct* thisData = mCachedInheritedData.GetStyleData(i);
- nsStyleStruct* otherData = aNewContext->mCachedInheritedData.GetStyleData(i);
- if (mBits & bit) {
- if (thisData == otherData) {
- DebugOnly<bool> shouldDelete = mCachedInheritedData.ClearStyleData(i);
- MOZ_ASSERT(!shouldDelete, "style struct refcount shouldn't be 0 when it "
- "is stored in two style contexts");
- }
- } else if (!(aNewContext->mBits & bit) && thisData && otherData) {
- mCachedInheritedData.SwapStyleData(i, aNewContext->mCachedInheritedData);
- }
- }
-
- for (nsStyleStructID i = nsStyleStructID_Reset_Start;
- i < nsStyleStructID_Reset_Start + nsStyleStructID_Reset_Count;
- i = nsStyleStructID(i + 1)) {
- uint32_t bit = nsCachedStyleData::GetBitForSID(i);
- if (!(aStructs & bit)) {
- continue;
- }
- if (!mCachedResetData) {
- mCachedResetData = new (mRuleNode->PresContext()) nsResetStyleData;
- }
- if (!aNewContext->mCachedResetData) {
- aNewContext->mCachedResetData =
- new (mRuleNode->PresContext()) nsResetStyleData;
- }
- nsStyleStruct* thisData = mCachedResetData->GetStyleData(i);
- nsStyleStruct* otherData = aNewContext->mCachedResetData->GetStyleData(i);
- if (mBits & bit) {
- if (thisData == otherData) {
- DebugOnly<bool> shouldDelete = mCachedResetData->ClearStyleData(i);
- MOZ_ASSERT(!shouldDelete, "style struct refcount shouldn't be 0 when it "
- "is stored in two style contexts");
- }
- } else if (!(aNewContext->mBits & bit) && thisData && otherData) {
- mCachedResetData->SwapStyleData(i, *aNewContext->mCachedResetData);
- }
- }
-}
-
-void
nsStyleContext::ClearCachedInheritedStyleDataOnDescendants(uint32_t aStructs)
{
if (mChild) {
nsStyleContext* child = mChild;
do {
child->DoClearCachedInheritedStyleDataOnDescendants(aStructs);
child = child->mNextSibling;
} while (mChild != child);
--- a/layout/style/nsStyleContext.h
+++ b/layout/style/nsStyleContext.h
@@ -390,36 +390,16 @@ public:
*
* This function violates style context tree immutability, and
* is a very low-level function and should only be used after verifying
* many conditions that make it safe to call.
*/
void MoveTo(nsStyleContext* aNewParent);
/**
- * Swaps owned style struct pointers between this and aNewContext, on
- * the assumption that aNewContext is the new style context for a frame
- * and this is the old one. aStructs indicates which structs to consider
- * swapping; only those which are owned in both this and aNewContext
- * will be swapped.
- *
- * Additionally, if there are identical struct pointers for one of the
- * structs indicated by aStructs, and it is not an owned struct on this,
- * then the cached struct slot on this will be set to null. If the struct
- * has been swapped on an ancestor, this style context (being the old one)
- * will be left caching the struct pointer on the new ancestor, despite
- * inheriting from the old ancestor. This is not normally a problem, as
- * this style context will usually be destroyed by being released at the
- * end of ElementRestyler::Restyle; but for style contexts held on to outside
- * of the frame, we need to clear out the cached pointer so that if we need
- * it again we'll re-fetch it from the new ancestor.
- */
- void SwapStyleData(nsStyleContext* aNewContext, uint32_t aStructs);
-
- /**
* On each descendant of this style context, clears out any cached inherited
* structs indicated in aStructs.
*/
void ClearCachedInheritedStyleDataOnDescendants(uint32_t aStructs);
/**
* Sets the NS_STYLE_INELIGIBLE_FOR_SHARING bit on this style context
* and its descendants. If it finds a descendant that has the bit