Bug 1077718 - Switch dynamic CounterStyle objects to use arena allocation. r=mats

This commit is contained in:
Xidorn Quan 2014-10-16 16:10:00 -04:00
parent ec4f90d64c
commit cf8e303b70
4 changed files with 58 additions and 13 deletions

View File

@ -34,6 +34,9 @@ public:
nsResetStyleData_id,
nsFrameList_id,
CustomCounterStyle_id,
DependentBuiltinCounterStyle_id,
First_nsStyleStruct_id,
DummyBeforeStyleStructs_id = First_nsStyleStruct_id - 1,

View File

@ -968,11 +968,6 @@ nsPresContext::Init(nsDeviceContext* aDeviceContext)
mAnimationManager = new nsAnimationManager(this);
// Since CounterStyleManager is also the name of a method of
// nsPresContext, it is necessary to prefix the class with the mozilla
// namespace here.
mCounterStyleManager = new mozilla::CounterStyleManager(this);
if (mDocument->GetDisplayDocument()) {
NS_ASSERTION(mDocument->GetDisplayDocument()->GetShell() &&
mDocument->GetDisplayDocument()->GetShell()->GetPresContext(),
@ -1100,6 +1095,10 @@ nsPresContext::SetShell(nsIPresShell* aShell)
mFontFaceSet->DestroyUserFontSet();
mFontFaceSet = nullptr;
}
if (mCounterStyleManager) {
mCounterStyleManager->Disconnect();
mCounterStyleManager = nullptr;
}
if (mShell) {
// Remove ourselves as the charset observer from the shell's doc, because
@ -1113,6 +1112,11 @@ nsPresContext::SetShell(nsIPresShell* aShell)
mShell = aShell;
if (mShell) {
// Since CounterStyleManager is also the name of a method of
// nsPresContext, it is necessary to prefix the class with the mozilla
// namespace here.
mCounterStyleManager = new mozilla::CounterStyleManager(this);
nsIDocument *doc = mShell->GetDocument();
NS_ASSERTION(doc, "expect document here");
if (doc) {
@ -1156,10 +1160,6 @@ nsPresContext::SetShell(nsIPresShell* aShell)
mRestyleManager->Disconnect();
mRestyleManager = nullptr;
}
if (mCounterStyleManager) {
mCounterStyleManager->Disconnect();
mCounterStyleManager = nullptr;
}
if (IsRoot()) {
// Have to cancel our plugin geometry timer, because the

View File

@ -966,12 +966,32 @@ public:
// DependentBuiltinCounterStyle is managed in the same way as
// CustomCounterStyle.
NS_INLINE_DECL_REFCOUNTING(DependentBuiltinCounterStyle)
NS_IMETHOD_(MozExternalRefCountType) AddRef() MOZ_OVERRIDE;
NS_IMETHOD_(MozExternalRefCountType) Release() MOZ_OVERRIDE;
void* operator new(size_t sz, nsPresContext* aPresContext) CPP_THROW_NEW
{
return aPresContext->PresShell()->AllocateByObjectID(
nsPresArena::DependentBuiltinCounterStyle_id, sz);
}
private:
void Destroy()
{
nsIPresShell* shell = mManager->PresContext()->PresShell();
this->~DependentBuiltinCounterStyle();
shell->FreeByObjectID(nsPresArena::DependentBuiltinCounterStyle_id, this);
}
CounterStyleManager* mManager;
nsAutoRefCnt mRefCnt;
NS_DECL_OWNINGTHREAD
};
NS_IMPL_ADDREF(DependentBuiltinCounterStyle)
NS_IMPL_RELEASE_WITH_DESTROY(DependentBuiltinCounterStyle, Destroy())
/* virtual */ CounterStyle*
DependentBuiltinCounterStyle::GetFallback()
{
@ -1064,9 +1084,23 @@ public:
// CustomCounterStyle should be reference-counted because it may be
// dereferenced from the manager but still referenced by nodes and
// frames before the style change is propagated.
NS_INLINE_DECL_REFCOUNTING(CustomCounterStyle)
NS_IMETHOD_(MozExternalRefCountType) AddRef() MOZ_OVERRIDE;
NS_IMETHOD_(MozExternalRefCountType) Release() MOZ_OVERRIDE;
void* operator new(size_t sz, nsPresContext* aPresContext) CPP_THROW_NEW
{
return aPresContext->PresShell()->AllocateByObjectID(
nsPresArena::CustomCounterStyle_id, sz);
}
private:
void Destroy()
{
nsIPresShell* shell = mManager->PresContext()->PresShell();
this->~CustomCounterStyle();
shell->FreeByObjectID(nsPresArena::CustomCounterStyle_id, this);
}
const nsTArray<nsString>& GetSymbols();
const nsTArray<AdditiveSymbol>& GetAdditiveSymbols();
@ -1139,8 +1173,14 @@ private:
// counter must be either a builtin style or a style whose system is
// not 'extends'.
CounterStyle* mExtendsRoot;
nsAutoRefCnt mRefCnt;
NS_DECL_OWNINGTHREAD
};
NS_IMPL_ADDREF(CustomCounterStyle)
NS_IMPL_RELEASE_WITH_DESTROY(CustomCounterStyle, Destroy())
void
CustomCounterStyle::ResetCachedData()
{
@ -1968,13 +2008,13 @@ CounterStyleManager::BuildCounterStyle(const nsSubstring& aName)
nsCSSCounterStyleRule* rule =
mPresContext->StyleSet()->CounterStyleRuleForName(mPresContext, aName);
if (rule) {
data = new CustomCounterStyle(this, rule);
data = new (mPresContext) CustomCounterStyle(this, rule);
} else {
int32_t type;
nsCSSKeyword keyword = nsCSSKeywords::LookupKeyword(aName);
if (nsCSSProps::FindKeyword(keyword, nsCSSProps::kListStyleKTable, type)) {
if (gBuiltinStyleTable[type].IsDependentStyle()) {
data = new DependentBuiltinCounterStyle(type, this);
data = new (mPresContext) DependentBuiltinCounterStyle(type, this);
} else {
data = GetBuiltinStyle(type);
}

View File

@ -176,6 +176,8 @@ public:
// be called when any counter style may be affected.
bool NotifyRuleChanged();
nsPresContext* PresContext() const { return mPresContext; }
NS_INLINE_DECL_REFCOUNTING(CounterStyleManager)
private: