Bug 1384114: Move mRefCnt, Destroy() and HasSingleReference() to GeckoStyleContext. r=bholley

MozReview-Commit-ID: 5XzFYcohl3m

--HG--
extra : rebase_source : e26c5c93fe66d5023ff3a7924cd8538cfcba8727
This commit is contained in:
Emilio Cobos Álvarez 2017-07-25 15:45:59 +02:00
Родитель 5729273ca7
Коммит 570c7fcbc6
4 изменённых файлов: 28 добавлений и 32 удалений

Просмотреть файл

@ -38,6 +38,7 @@ GeckoStyleContext::GeckoStyleContext(GeckoStyleContext* aParent,
bool aSkipParentDisplayBasedStyleFixup)
: nsStyleContext(aParent, aPseudoTag, aPseudoType)
, mCachedResetData(nullptr)
, mRefCnt(0)
, mChild(nullptr)
, mEmptyChild(nullptr)
, mRuleNode(Move(aRuleNode))
@ -81,6 +82,21 @@ GeckoStyleContext::operator new(size_t sz, nsPresContext* aPresContext)
AllocateByObjectID(eArenaObjectID_GeckoStyleContext, sz);
}
// Overridden to prevent the global delete from being called, since the memory
// came out of an nsIArena instead of the global delete operator's heap.
void
GeckoStyleContext::Destroy()
{
// Get the pres context.
RefPtr<nsPresContext> presContext = PresContext();
// Call our destructor.
this->~GeckoStyleContext();
// Don't let the memory be freed, since it will be recycled
// instead. Don't call the global operator delete.
presContext->PresShell()->
FreeByObjectID(eArenaObjectID_GeckoStyleContext, this);
}
GeckoStyleContext::~GeckoStyleContext()
{
nsPresContext *presContext = PresContext();

Просмотреть файл

@ -138,6 +138,13 @@ public:
return mRuleNode;
}
bool HasSingleReference() const {
NS_ASSERTION(mRefCnt != 0,
"do not call HasSingleReference on a newly created "
"nsStyleContext with no references yet");
return mRefCnt == 1;
}
void AddRef() {
if (mRefCnt == UINT32_MAX) {
NS_WARNING("refcount overflow, leaking object");
@ -220,6 +227,8 @@ public:
nsResetStyleData* mCachedResetData; // Cached reset style data.
nsInheritedStyleData mCachedInheritedData; // Cached inherited style data
uint32_t mRefCnt;
#ifdef DEBUG
void AssertStructsNotUsedElsewhere(GeckoStyleContext* aDestroyingContext,
int32_t aLevels) const;
@ -228,6 +237,7 @@ public:
private:
// Helper for ClearCachedInheritedStyleDataOnDescendants.
void DoClearCachedInheritedStyleDataOnDescendants(uint32_t aStructs);
void Destroy();
// Children are kept in two circularly-linked lists. The list anchor
// is not part of the list (null for empty), and we point to the first

Просмотреть файл

@ -84,7 +84,6 @@ nsStyleContext::nsStyleContext(nsStyleContext* aParent,
: mParent(aParent)
, mPseudoTag(aPseudoTag)
, mBits(((uint64_t)aPseudoType) << NS_STYLE_CONTEXT_TYPE_SHIFT)
, mRefCnt(0)
#ifdef DEBUG
, mFrameRefCnt(0)
#endif
@ -435,7 +434,8 @@ void nsStyleContext::List(FILE* out, int32_t aIndent, bool aListDescendants)
str.AppendLiteral(" ");
}
str.Append(nsPrintfCString("%p(%d) parent=%p ",
(void*)this, mRefCnt, (void *)mParent));
(void*)this, IsGecko() ? AsGecko()->mRefCnt : 0,
(void *)mParent));
if (mPseudoTag) {
nsAutoString buffer;
mPseudoTag->ToString(buffer);
@ -472,25 +472,6 @@ void nsStyleContext::List(FILE* out, int32_t aIndent, bool aListDescendants)
}
#endif
// Overridden to prevent the global delete from being called, since the memory
// came out of an nsIArena instead of the global delete operator's heap.
void
nsStyleContext::Destroy()
{
if (IsGecko()) {
// Get the pres context.
RefPtr<nsPresContext> presContext = PresContext();
// Call our destructor.
this->AsGecko()->~GeckoStyleContext();
// Don't let the memory be freed, since it will be recycled
// instead. Don't call the global operator delete.
presContext->PresShell()->
FreeByObjectID(eArenaObjectID_GeckoStyleContext, this);
} else {
delete static_cast<ServoStyleContext*>(this);
}
}
already_AddRefed<GeckoStyleContext>
NS_NewStyleContext(GeckoStyleContext* aParentContext,
nsIAtom* aPseudoTag,

Просмотреть файл

@ -62,8 +62,6 @@ public:
#endif
MOZ_DECL_STYLO_CONVERT_METHODS(mozilla::GeckoStyleContext, mozilla::ServoStyleContext);
void Destroy();
// These two methods are for use by ArenaRefPtr.
static mozilla::ArenaObjectID ArenaObjectID()
{
@ -91,13 +89,6 @@ public:
}
#endif
bool HasSingleReference() const {
NS_ASSERTION(mRefCnt != 0,
"do not call HasSingleReference on a newly created "
"nsStyleContext with no references yet");
return mRefCnt == 1;
}
inline nsPresContext* PresContext() const;
inline mozilla::GeckoStyleContext* GetParent() const;
@ -360,8 +351,6 @@ protected:
// nsStyleStruct.h.
uint64_t mBits;
uint32_t mRefCnt;
#ifdef DEBUG
uint32_t mFrameRefCnt; // number of frames that use this
// as their style context