Bug 1479398: Micro-optimize is_root to avoid poking at the parent in the common case. r=xidorn

Summary:
We can discard the common case of an element having another element or document
fragment parent, which is the common case.

Then we can discard detached subtrees looking at is_in_document().

The only case where we have a non-content parent is the document case:

  https://searchfox.org/mozilla-central/rev/033d45ca70ff32acf04286244644d19308c359d5/dom/base/Element.cpp#1683

Reviewers: xidorn

Tags: #secure-revision

Bug #: 1479398

Differential Revision: https://phabricator.services.mozilla.com/D2505

MozReview-Commit-ID: H2mWHBmk5g1
This commit is contained in:
Emilio Cobos Álvarez 2018-07-30 13:10:09 +02:00
Родитель c8f7722310
Коммит c383561848
1 изменённых файлов: 6 добавлений и 6 удалений

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

@ -2087,15 +2087,15 @@ impl<'le> ::selectors::Element for GeckoElement<'le> {
#[inline]
fn is_root(&self) -> bool {
let parent_node = match self.as_node().parent_node() {
Some(parent_node) => parent_node,
None => return false,
};
if !parent_node.is_document() {
if self.as_node().get_bool_flag(nsINode_BooleanFlag::ParentIsContent) {
return false;
}
if !self.as_node().is_in_document() {
return false;
}
debug_assert!(self.as_node().parent_node().map_or(false, |p| p.is_document()));
unsafe { bindings::Gecko_IsRootElement(self.0) }
}