Bug 1444580: Devirtualize GetRootElementInternal, and move nsINode overrides to nsIDocument. r=smaug

MozReview-Commit-ID: IlgHXhETOIa
This commit is contained in:
Emilio Cobos Álvarez 2018-03-11 13:31:31 +01:00
Родитель f73bf76b95
Коммит 288a10bc0b
3 изменённых файлов: 53 добавлений и 58 удалений

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

@ -4184,9 +4184,9 @@ nsIDocument::FindContentForSubDocument(nsIDocument *aDocument) const
} }
bool bool
nsDocument::IsNodeOfType(uint32_t aFlags) const nsIDocument::IsNodeOfType(uint32_t aFlags) const
{ {
return !(aFlags & ~eDOCUMENT); return !(aFlags & ~eDOCUMENT);
} }
Element* Element*
@ -4203,7 +4203,7 @@ nsIDocument::GetUnfocusedKeyEventTarget()
} }
Element* Element*
nsDocument::GetRootElementInternal() const nsIDocument::GetRootElementInternal() const
{ {
// We invoke GetRootElement() immediately before the servo traversal, so we // We invoke GetRootElement() immediately before the servo traversal, so we
// should always have a cache hit from Servo. // should always have a cache hit from Servo.
@ -4215,36 +4215,19 @@ nsDocument::GetRootElementInternal() const
for (i = mChildren.ChildCount(); i > 0; --i) { for (i = mChildren.ChildCount(); i > 0; --i) {
nsIContent* child = mChildren.ChildAt(i - 1); nsIContent* child = mChildren.ChildAt(i - 1);
if (child->IsElement()) { if (child->IsElement()) {
const_cast<nsDocument*>(this)->mCachedRootElement = child->AsElement(); const_cast<nsIDocument*>(this)->mCachedRootElement = child->AsElement();
return child->AsElement(); return child->AsElement();
} }
} }
const_cast<nsDocument*>(this)->mCachedRootElement = nullptr; const_cast<nsIDocument*>(this)->mCachedRootElement = nullptr;
return nullptr; return nullptr;
} }
nsIContent *
nsDocument::GetChildAt_Deprecated(uint32_t aIndex) const
{
return mChildren.GetSafeChildAt(aIndex);
}
int32_t
nsDocument::ComputeIndexOf(const nsINode* aPossibleChild) const
{
return mChildren.IndexOfChild(aPossibleChild);
}
uint32_t
nsDocument::GetChildCount() const
{
return mChildren.ChildCount();
}
nsresult nsresult
nsDocument::InsertChildBefore(nsIContent* aKid, nsIContent* aBeforeThis, nsIDocument::InsertChildBefore(nsIContent* aKid,
bool aNotify) nsIContent* aBeforeThis,
bool aNotify)
{ {
if (aKid->IsElement() && GetRootElement()) { if (aKid->IsElement() && GetRootElement()) {
NS_WARNING("Inserting root element when we already have one"); NS_WARNING("Inserting root element when we already have one");
@ -4258,8 +4241,9 @@ nsDocument::InsertChildBefore(nsIContent* aKid, nsIContent* aBeforeThis,
} }
nsresult nsresult
nsDocument::InsertChildAt_Deprecated(nsIContent* aKid, uint32_t aIndex, nsIDocument::InsertChildAt_Deprecated(nsIContent* aKid,
bool aNotify) uint32_t aIndex,
bool aNotify)
{ {
if (aKid->IsElement() && GetRootElement()) { if (aKid->IsElement() && GetRootElement()) {
NS_WARNING("Inserting root element when we already have one"); NS_WARNING("Inserting root element when we already have one");
@ -4270,7 +4254,7 @@ nsDocument::InsertChildAt_Deprecated(nsIContent* aKid, uint32_t aIndex,
} }
void void
nsDocument::RemoveChildAt_Deprecated(uint32_t aIndex, bool aNotify) nsIDocument::RemoveChildAt_Deprecated(uint32_t aIndex, bool aNotify)
{ {
nsCOMPtr<nsIContent> oldKid = GetChildAt_Deprecated(aIndex); nsCOMPtr<nsIContent> oldKid = GetChildAt_Deprecated(aIndex);
if (!oldKid) { if (!oldKid) {
@ -4297,7 +4281,7 @@ nsDocument::RemoveChildAt_Deprecated(uint32_t aIndex, bool aNotify)
} }
void void
nsDocument::RemoveChildNode(nsIContent* aKid, bool aNotify) nsIDocument::RemoveChildNode(nsIContent* aKid, bool aNotify)
{ {
if (aKid->IsElement()) { if (aKid->IsElement()) {
// Destroy the link map up front before we mess with the child list. // Destroy the link map up front before we mess with the child list.
@ -8763,7 +8747,7 @@ nsDocument::MutationEventDispatched(nsINode* aTarget)
} }
void void
nsDocument::DestroyElementMaps() nsIDocument::DestroyElementMaps()
{ {
#ifdef DEBUG #ifdef DEBUG
mStyledLinksCleared = true; mStyledLinksCleared = true;

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

@ -45,7 +45,6 @@
#include "nsIApplicationCacheContainer.h" #include "nsIApplicationCacheContainer.h"
#include "mozilla/StyleSetHandle.h" #include "mozilla/StyleSetHandle.h"
#include "PLDHashTable.h" #include "PLDHashTable.h"
#include "nsAttrAndChildArray.h"
#include "nsDOMAttributeMap.h" #include "nsDOMAttributeMap.h"
#include "nsIContentViewer.h" #include "nsIContentViewer.h"
#include "nsIInterfaceRequestor.h" #include "nsIInterfaceRequestor.h"
@ -369,8 +368,6 @@ public:
return mTimelines; return mTimelines;
} }
virtual Element* GetRootElementInternal() const override;
virtual nsIChannel* GetChannel() const override { virtual nsIChannel* GetChannel() const override {
return mChannel; return mChannel;
} }
@ -407,23 +404,6 @@ public:
virtual void WillDispatchMutationEvent(nsINode* aTarget) override; virtual void WillDispatchMutationEvent(nsINode* aTarget) override;
virtual void MutationEventDispatched(nsINode* aTarget) override; virtual void MutationEventDispatched(nsINode* aTarget) override;
// nsINode
virtual bool IsNodeOfType(uint32_t aFlags) const override;
virtual nsIContent *GetChildAt_Deprecated(uint32_t aIndex) const override;
virtual int32_t ComputeIndexOf(const nsINode* aPossibleChild) const override;
virtual uint32_t GetChildCount() const override;
virtual nsresult InsertChildBefore(nsIContent* aKid, nsIContent* aBeforeThis,
bool aNotify) override;
virtual nsresult InsertChildAt_Deprecated(nsIContent* aKid, uint32_t aIndex,
bool aNotify) override;
virtual void RemoveChildAt_Deprecated(uint32_t aIndex, bool aNotify) override;
virtual void RemoveChildNode(nsIContent* aKid, bool aNotify) override;
virtual nsresult Clone(mozilla::dom::NodeInfo *aNodeInfo, nsINode **aResult,
bool aPreallocateChildren) const override
{
return NS_ERROR_NOT_IMPLEMENTED;
}
// nsIRadioGroupContainer // nsIRadioGroupContainer
NS_IMETHOD WalkRadioGroup(const nsAString& aName, NS_IMETHOD WalkRadioGroup(const nsAString& aName,
nsIRadioVisitor* aVisitor, nsIRadioVisitor* aVisitor,
@ -695,10 +675,6 @@ protected:
NotNull<const Encoding*>& aEncoding, NotNull<const Encoding*>& aEncoding,
nsHtml5TreeOpExecutor* aExecutor); nsHtml5TreeOpExecutor* aExecutor);
// Call this before the document does something that will unbind all content.
// That will stop us from doing a lot of work as each element is removed.
void DestroyElementMaps();
nsIContent* GetFirstBaseNodeWithHref(); nsIContent* GetFirstBaseNodeWithHref();
nsresult SetFirstBaseNodeWithHref(nsIContent *node); nsresult SetFirstBaseNodeWithHref(nsIContent *node);
@ -735,9 +711,6 @@ protected:
void EnsureOnloadBlocker(); void EnsureOnloadBlocker();
// Array of owning references to all children
nsAttrAndChildArray mChildren;
// Tracker for animations that are waiting to start. // Tracker for animations that are waiting to start.
// nullptr until GetOrCreatePendingAnimationTracker is called. // nullptr until GetOrCreatePendingAnimationTracker is called.
RefPtr<mozilla::PendingAnimationTracker> mPendingAnimationTracker; RefPtr<mozilla::PendingAnimationTracker> mPendingAnimationTracker;

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

@ -8,6 +8,7 @@
#include "jsfriendapi.h" #include "jsfriendapi.h"
#include "mozilla/FlushType.h" // for enum #include "mozilla/FlushType.h" // for enum
#include "nsAttrAndChildArray.h"
#include "nsAutoPtr.h" // for member #include "nsAutoPtr.h" // for member
#include "nsCOMArray.h" // for member #include "nsCOMArray.h" // for member
#include "nsCompatibility.h" // for member #include "nsCompatibility.h" // for member
@ -336,6 +337,36 @@ public:
virtual void SetSuppressParserErrorConsoleMessages(bool aSuppress) {} virtual void SetSuppressParserErrorConsoleMessages(bool aSuppress) {}
virtual bool SuppressParserErrorConsoleMessages() { return false; } virtual bool SuppressParserErrorConsoleMessages() { return false; }
// nsINode
bool IsNodeOfType(uint32_t aFlags) const final;
nsIContent* GetChildAt_Deprecated(uint32_t aIndex) const final
{
return mChildren.GetSafeChildAt(aIndex);
}
int32_t ComputeIndexOf(const nsINode* aPossibleChild) const final
{
return mChildren.IndexOfChild(aPossibleChild);
}
uint32_t GetChildCount() const final
{
return mChildren.ChildCount();
}
nsresult InsertChildBefore(nsIContent* aKid, nsIContent* aBeforeThis,
bool aNotify) override;
nsresult InsertChildAt_Deprecated(nsIContent* aKid, uint32_t aIndex,
bool aNotify) override;
void RemoveChildAt_Deprecated(uint32_t aIndex, bool aNotify) final;
void RemoveChildNode(nsIContent* aKid, bool aNotify) final;
nsresult Clone(mozilla::dom::NodeInfo* aNodeInfo,
nsINode **aResult,
bool aPreallocateChildren) const override
{
return NS_ERROR_NOT_IMPLEMENTED;
}
/** /**
* Signal that the document title may have changed * Signal that the document title may have changed
* (see nsDocument::GetTitle). * (see nsDocument::GetTitle).
@ -1180,7 +1211,11 @@ public:
mozilla::Maybe<mozilla::dom::ServiceWorkerDescriptor> GetController() const; mozilla::Maybe<mozilla::dom::ServiceWorkerDescriptor> GetController() const;
protected: protected:
virtual Element* GetRootElementInternal() const = 0; // Call this before the document does something that will unbind all content.
// That will stop us from doing a lot of work as each element is removed.
void DestroyElementMaps();
Element* GetRootElementInternal() const;
void DoNotifyPossibleTitleChange(); void DoNotifyPossibleTitleChange();
void SetPageUnloadingEventTimeStamp() void SetPageUnloadingEventTimeStamp()
@ -4075,6 +4110,9 @@ protected:
// A set of responsive images keyed by address pointer. // A set of responsive images keyed by address pointer.
nsTHashtable<nsPtrHashKey<mozilla::dom::HTMLImageElement>> mResponsiveContent; nsTHashtable<nsPtrHashKey<mozilla::dom::HTMLImageElement>> mResponsiveContent;
// Array of owning references to all children
nsAttrAndChildArray mChildren;
public: public:
js::ExpandoAndGeneration mExpandoAndGeneration; js::ExpandoAndGeneration mExpandoAndGeneration;