From bee7cbad0d0d6a57a62ba11cf1b80710c4ad186d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Emilio=20Cobos=20=C3=81lvarez?= Date: Mon, 30 Jul 2018 13:10:09 +0200 Subject: [PATCH] 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 --- components/style/gecko/wrapper.rs | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/components/style/gecko/wrapper.rs b/components/style/gecko/wrapper.rs index eed9ebe00af..b00755a1d5b 100644 --- a/components/style/gecko/wrapper.rs +++ b/components/style/gecko/wrapper.rs @@ -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) } }