Skip to content

Commit

Permalink
style: Micro-optimize is_root to avoid poking at the parent in the co…
Browse files Browse the repository at this point in the history
…mmon 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
  • Loading branch information
emilio committed Aug 7, 2018
1 parent eb49995 commit bee7cba
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions components/style/gecko/wrapper.rs
Expand Up @@ -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 self.as_node().get_bool_flag(nsINode_BooleanFlag::ParentIsContent) {
return false;
}

if !parent_node.is_document() {
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) }
}

Expand Down

0 comments on commit bee7cba

Please sign in to comment.