style: Micro-optimize is_root to avoid poking at the parent in the common case.

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

Differential Revision: https://phabricator.services.mozilla.com/D2505
This commit is contained in:
Emilio Cobos Álvarez 2018-07-30 13:10:09 +02:00
parent eb49995737
commit bee7cbad0d
No known key found for this signature in database
GPG key ID: 056B727BB9C1027C

View file

@ -2074,15 +2074,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) }
}