Bug 1296509 - Optimize GetFlattenedTreeParent. r=smaug

We need to call it on some hot paths in stylo, and this allows us to do
quick inline check before delegating to the slow path.
This commit is contained in:
Bobby Holley 2016-08-18 17:03:49 -07:00
Родитель 1d6f2ecf7c
Коммит 412f98cac5
14 изменённых файлов: 70 добавлений и 9 удалений

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

@ -14,6 +14,7 @@
#include "mozilla/UniquePtr.h"
#include "nsIContent.h"
#include "nsIContentInlines.h"
#include "nsString.h"
#include "nsTArray.h"
#include "nsRefPtrHashtable.h"

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

@ -151,10 +151,15 @@ nsIContent::FindFirstNonChromeOnlyAccessContent() const
return nullptr;
}
nsIContent*
nsIContent::GetFlattenedTreeParent() const
nsINode*
nsIContent::GetFlattenedTreeParentNodeInternal() const
{
nsIContent* parent = GetParent();
nsINode* parentNode = GetParentNode();
if (!parentNode || !parentNode->IsContent()) {
MOZ_ASSERT(!parentNode || parentNode == OwnerDoc());
return parentNode;
}
nsIContent* parent = parentNode->AsContent();
if (parent && nsContentUtils::HasDistributedChildren(parent) &&
nsContentUtils::IsInSameAnonymousTree(parent, this)) {

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

@ -107,6 +107,7 @@
#include "nsIChromeRegistry.h"
#include "nsIConsoleService.h"
#include "nsIContent.h"
#include "nsIContentInlines.h"
#include "nsIContentSecurityPolicy.h"
#include "nsIContentSink.h"
#include "nsIContentViewer.h"

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

@ -719,13 +719,15 @@ public:
virtual void SetXBLInsertionParent(nsIContent* aContent) = 0;
/**
* Returns the content node that is the parent of this node in the flattened
* tree. For nodes that are not filtered into an insertion point, this
* simply returns their DOM parent in the original DOM tree.
*
* @return the flattened tree parent
* Same as GetFlattenedTreeParentNode, but returns null if the parent is
* non-nsIContent.
*/
nsIContent *GetFlattenedTreeParent() const;
inline nsIContent *GetFlattenedTreeParent() const;
/**
* Helper method, which we leave public so that it's accessible from nsINode.
*/
nsINode *GetFlattenedTreeParentNodeInternal() const;
/**
* Gets the custom element data used by web components custom element.

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

@ -33,5 +33,39 @@ inline mozilla::dom::ShadowRoot* nsIContent::GetShadowRoot() const
return AsElement()->FastGetShadowRoot();
}
inline nsINode* nsINode::GetFlattenedTreeParentNode() const
{
nsINode* parent = GetParentNode();
// Try to short-circuit past the complicated and not-exactly-fast logic for
// computing the flattened parent.
//
// There are three cases where we need might something other than parentNode:
// (1) The node is an explicit child of an XBL-bound element, re-bound
// to an XBL insertion point.
// (2) The node is a top-level element in a shadow tree, whose flattened
// parent is the host element (as opposed to the actual parent which
// is the shadow root).
// (3) The node is an explicit child of an element with a shadow root,
// re-bound to an insertion point.
bool needSlowCall = HasFlag(NODE_MAY_BE_IN_BINDING_MNGR) ||
IsInShadowTree() ||
(parent && parent->IsContent() &&
parent->AsContent()->GetShadowRoot());
if (MOZ_UNLIKELY(needSlowCall)) {
MOZ_ASSERT(IsContent());
return AsContent()->GetFlattenedTreeParentNodeInternal();
}
return parent;
}
inline nsIContent*
nsIContent::GetFlattenedTreeParent() const
{
nsINode* parent = GetFlattenedTreeParentNode();
return (parent && parent->IsContent()) ? parent->AsContent() : nullptr;
}
#endif // nsIContentInlines_h

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

@ -928,6 +928,16 @@ public:
return mParent;
}
/**
* Returns the node that is the parent of this node in the flattened
* tree. This differs from the normal parent if the node is filtered
* into an insertion point, or if the node is a direct child of a
* shadow root.
*
* @return the flattened tree parent
*/
inline nsINode* GetFlattenedTreeParentNode() const;
/**
* Get the parent nsINode for this node if it is an Element.
* @return the parent node

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

@ -29,6 +29,7 @@
#include "nsCOMPtr.h"
#include "nsFocusManager.h"
#include "nsIContent.h"
#include "nsIContentInlines.h"
#include "nsIDocument.h"
#include "nsIFrame.h"
#include "nsIWidget.h"

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

@ -17,6 +17,7 @@
#include "nsGenericHTMLElement.h"
#include "nsGkAtoms.h"
#include "nsDOMTokenList.h"
#include "nsIContentInlines.h"
#include "nsIDocument.h"
#include "nsIDOMEvent.h"
#include "nsIDOMStyleSheet.h"

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

@ -10,6 +10,7 @@
#include "nsSMILAnimationController.h"
#include "nsSMILAnimationFunction.h"
#include "nsContentUtils.h"
#include "nsIContentInlines.h"
#include "nsIURI.h"
#include "prtime.h"

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

@ -9,6 +9,7 @@
#include "mozilla/dom/FromParser.h"
#include "nsAutoPtr.h"
#include "nsIContentInlines.h"
#include "nsISVGPoint.h"
#include "nsSVGEnum.h"
#include "nsSVGLength2.h"

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

@ -16,6 +16,7 @@
#include "nsAutoPtr.h"
#include "nsClassHashtable.h"
#include "nsContainerFrame.h"
#include "nsIContentInlines.h"
#include "mozilla/SplayTree.h"
#include "mozilla/RestyleLogging.h"
#include "GeckoProfiler.h"

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

@ -23,6 +23,7 @@
#include "nsFrameList.h"
#include "nsPlaceholderFrame.h"
#include "nsIContent.h"
#include "nsIContentInlines.h"
#include "nsContentUtils.h"
#include "nsCSSPseudoElements.h"
#include "nsIAtom.h"

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

@ -18,6 +18,7 @@
#include "nsPresContext.h"
#include "nsRenderingContext.h"
#include "nsIFrameInlines.h"
#include "nsIContentInlines.h"
using namespace mozilla;
using namespace mozilla::gfx;

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

@ -14,6 +14,7 @@
#include "nsISupportsArray.h"
#include "nsString.h"
#include "nsIStyleSheetLinkingElement.h"
#include "nsIContentInlines.h"
#include "nsIDOMElement.h"
#include "nsIDocument.h"
#include "nsIPresShell.h"