mirror of
https://github.com/servo/servo.git
synced 2025-07-22 23:03:42 +01:00
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:
parent
eb49995737
commit
bee7cbad0d
1 changed files with 6 additions and 6 deletions
|
@ -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) }
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue