Bug 77999 - Part 4: Mark nsCSSRuleProcessors as ready for expiration from the RuleProcessorCache once no nsStyleSets are using them. r=dbaron

We want the RuleProcessorCache to start considering a given
nsCSSRuleProcessor as ready for expiration only once no nsStyleSets are
using it.
This commit is contained in:
Cameron McCormack 2015-06-26 13:52:47 +10:00
parent b21e55647a
commit 0274cb2bf2
2 changed files with 25 additions and 0 deletions

View File

@ -1015,6 +1015,7 @@ nsCSSRuleProcessor::nsCSSRuleProcessor(const sheet_array_type& aSheets,
: UniquePtr<nsMediaQueryResultCacheKey>())
, mLastPresContext(nullptr)
, mScopeElement(aScopeElement)
, mStyleSetRefCnt(0)
, mSheetType(aSheetType)
, mIsShared(aIsShared)
, mMustGatherDocumentRules(aIsShared)
@ -1037,6 +1038,7 @@ nsCSSRuleProcessor::~nsCSSRuleProcessor()
RuleProcessorCache::RemoveRuleProcessor(this);
}
MOZ_ASSERT(!mExpirationState.IsTracked());
MOZ_ASSERT(mStyleSetRefCnt == 0);
ClearSheets();
ClearRuleCascades();
}
@ -3756,6 +3758,25 @@ nsCSSRuleProcessor::TakeDocumentRulesAndCacheKey(
#endif
}
void
nsCSSRuleProcessor::AddStyleSetRef()
{
MOZ_ASSERT(mIsShared);
if (++mStyleSetRefCnt == 1) {
RuleProcessorCache::StopTracking(this);
}
}
void
nsCSSRuleProcessor::ReleaseStyleSetRef()
{
MOZ_ASSERT(mIsShared);
MOZ_ASSERT(mStyleSetRefCnt > 0);
if (--mStyleSetRefCnt == 0 && mInRuleProcessorCache) {
RuleProcessorCache::StartTracking(this);
}
}
// TreeMatchContext and AncestorFilter out of line methods
void
TreeMatchContext::InitAncestors(Element *aElement)

View File

@ -21,6 +21,7 @@
#include "nsAutoPtr.h"
#include "nsExpirationTracker.h"
#include "nsRuleWalker.h"
#include "mozilla/RefCountType.h"
#include "mozilla/UniquePtr.h"
struct CascadeEnumData;
@ -175,6 +176,8 @@ public:
bool IsShared() const { return mIsShared; }
nsExpirationState* GetExpirationState() { return &mExpirationState; }
void AddStyleSetRef();
void ReleaseStyleSetRef();
void SetInRuleProcessorCache(bool aVal) {
MOZ_ASSERT(mIsShared);
printf("%p SetInRuleProcessorCache %d\n", this, aVal);
@ -239,6 +242,7 @@ private:
nsDocumentRuleResultCacheKey mDocumentCacheKey;
nsExpirationState mExpirationState;
MozRefCountType mStyleSetRefCnt;
// type of stylesheet using this processor
uint8_t mSheetType; // == nsStyleSet::sheetType