Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

stylo: Optimize some FFI calls #15353

Merged
merged 3 commits into from Feb 3, 2017
Merged
Changes from all commits
Commits
File filter...
Filter file types
Jump to…
Jump to file
Failed to load files.

Always

Just for now

@@ -235,6 +235,7 @@ mod bindings {
.include(add_include("mozilla/Keyframe.h"))
.include(add_include("mozilla/ServoElementSnapshot.h"))
.include(add_include("mozilla/dom/Element.h"))
.include(add_include("mozilla/dom/NameSpaceConstants.h"))
.include(add_include("mozilla/ServoBindings.h"))
.include(add_include("nsMediaFeatures.h"))
.include(add_include("nsMediaList.h"))
@@ -258,6 +259,7 @@ mod bindings {
"BORDER_COLOR_.*",
"BORDER_STYLE_.*",
"mozilla::SERVO_PREF_.*",
"kNameSpaceID_.*",
];
let whitelist = [
"RawGecko.*",
@@ -25,12 +25,12 @@ use gecko::snapshot_helpers;
use gecko_bindings::bindings;
use gecko_bindings::bindings::{Gecko_DropStyleChildrenIterator, Gecko_MaybeCreateStyleChildrenIterator};
use gecko_bindings::bindings::{Gecko_ElementState, Gecko_GetLastChild, Gecko_GetNextStyleChild};
use gecko_bindings::bindings::{Gecko_GetServoDeclarationBlock, Gecko_IsHTMLElementInHTMLDocument};
use gecko_bindings::bindings::{Gecko_IsLink, Gecko_IsRootElement, Gecko_MatchesElement};
use gecko_bindings::bindings::{Gecko_IsUnvisitedLink, Gecko_IsVisitedLink, Gecko_Namespace};
use gecko_bindings::bindings::{Gecko_SetNodeFlags, Gecko_UnsetNodeFlags};
use gecko_bindings::bindings::Gecko_ClassOrClassList;
use gecko_bindings::bindings::Gecko_GetAnimationRule;
use gecko_bindings::bindings::Gecko_GetServoDeclarationBlock;
use gecko_bindings::bindings::Gecko_GetStyleContext;
use gecko_bindings::structs;
use gecko_bindings::structs::{RawGeckoElement, RawGeckoNode};
@@ -83,11 +83,20 @@ impl<'ln> GeckoNode<'ln> {
GeckoNode(&content._base)
}

fn flags(&self) -> u32 {
(self.0)._base._base_1.mFlags
}

fn node_info(&self) -> &structs::NodeInfo {
debug_assert!(!self.0.mNodeInfo.mRawPtr.is_null());
unsafe { &*self.0.mNodeInfo.mRawPtr }
}

fn owner_doc(&self) -> &structs::nsIDocument {
debug_assert!(!self.node_info().mDocument.is_null());
unsafe { &*self.node_info().mDocument }
}

fn first_child(&self) -> Option<GeckoNode<'ln>> {
unsafe { self.0.mFirstChild.as_ref().map(GeckoNode::from_content) }
}
@@ -103,6 +112,32 @@ impl<'ln> GeckoNode<'ln> {
fn next_sibling(&self) -> Option<GeckoNode<'ln>> {
unsafe { self.0.mNextSibling.as_ref().map(GeckoNode::from_content) }
}

/// WARNING: This logic is duplicated in Gecko's FlattenedTreeParentIsParent.
/// Make sure to mirror any modifications in both places.
fn flattened_tree_parent_is_parent(&self) -> bool {
use ::gecko_bindings::structs::*;
let flags = self.flags();
if flags & (NODE_MAY_BE_IN_BINDING_MNGR as u32 |
NODE_IS_IN_SHADOW_TREE as u32) != 0 {
return false;
}

let parent = unsafe { self.0.mParent.as_ref() }.map(GeckoNode);
let parent_el = parent.and_then(|p| p.as_element());
if flags & (NODE_IS_NATIVE_ANONYMOUS_ROOT as u32) != 0 &&
parent_el.map_or(false, |el| el.is_root())
{
return false;
}

if parent_el.map_or(false, |el| el.has_shadow_root()) {
return false;
}

true
}

}

impl<'ln> NodeInfo for GeckoNode<'ln> {
@@ -168,7 +203,13 @@ impl<'ln> TNode for GeckoNode<'ln> {
}

fn parent_node(&self) -> Option<Self> {
unsafe { bindings::Gecko_GetParentNode(self.0).map(GeckoNode) }
let fast_path = self.flattened_tree_parent_is_parent();
debug_assert!(fast_path == unsafe { bindings::Gecko_FlattenedTreeParentIsParent(self.0) });
if fast_path {
unsafe { self.0.mParent.as_ref().map(GeckoNode) }
} else {
unsafe { bindings::Gecko_GetParentNode(self.0).map(GeckoNode) }
}
}

fn is_in_doc(&self) -> bool {
@@ -278,6 +319,17 @@ impl<'le> GeckoElement<'le> {
unsafe { Gecko_UnsetNodeFlags(self.as_node().0, flags) }
}

/// Returns true if this element has a shadow root.
fn has_shadow_root(&self) -> bool {
self.get_dom_slots().map_or(false, |slots| !slots.mShadowRoot.mRawPtr.is_null())
}

/// Returns a reference to the DOM slots for this Element, if they exist.
fn get_dom_slots(&self) -> Option<&structs::FragmentOrElement_nsDOMSlots> {
let slots = self.as_node().0.mSlots as *const structs::FragmentOrElement_nsDOMSlots;
unsafe { slots.as_ref() }
}

/// Clear the element data for a given element.
pub fn clear_data(&self) {
let ptr = self.0.mServoData.get();
@@ -440,7 +492,8 @@ impl<'le> PresentationalHintsSynthetizer for GeckoElement<'le> {

impl<'le> ::selectors::Element for GeckoElement<'le> {
fn parent_element(&self) -> Option<Self> {
unsafe { bindings::Gecko_GetParentElement(self.0).map(GeckoElement) }
let parent_node = self.as_node().parent_node();
parent_node.and_then(|n| n.as_element())
}

fn first_child_element(&self) -> Option<Self> {
@@ -565,9 +618,10 @@ impl<'le> ::selectors::Element for GeckoElement<'le> {
}

fn is_html_element_in_html_document(&self) -> bool {
unsafe {
Gecko_IsHTMLElementInHTMLDocument(self.0)
}
let node = self.as_node();
let node_info = node.node_info();
node_info.mInner.mNamespaceID == (structs::root::kNameSpaceID_XHTML as i32) &&
node.owner_doc().mType == structs::root::nsIDocument_Type::eHTML
}
}

@@ -311,6 +311,10 @@ extern "C" {
extern "C" {
pub fn Gecko_IsInDocument(node: RawGeckoNodeBorrowed) -> bool;
}
extern "C" {
pub fn Gecko_FlattenedTreeParentIsParent(node: RawGeckoNodeBorrowed)
-> bool;
}
extern "C" {
pub fn Gecko_GetParentNode(node: RawGeckoNodeBorrowed)
-> RawGeckoNodeBorrowedOrNull;
@@ -331,10 +335,6 @@ extern "C" {
pub fn Gecko_GetNextSibling(node: RawGeckoNodeBorrowed)
-> RawGeckoNodeBorrowedOrNull;
}
extern "C" {
pub fn Gecko_GetParentElement(element: RawGeckoElementBorrowed)
-> RawGeckoElementBorrowedOrNull;
}
extern "C" {
pub fn Gecko_GetFirstChildElement(element: RawGeckoElementBorrowed)
-> RawGeckoElementBorrowedOrNull;
@@ -376,10 +376,6 @@ extern "C" {
extern "C" {
pub fn Gecko_ElementState(element: RawGeckoElementBorrowed) -> u16;
}
extern "C" {
pub fn Gecko_IsHTMLElementInHTMLDocument(element: RawGeckoElementBorrowed)
-> bool;
}
extern "C" {
pub fn Gecko_IsLink(element: RawGeckoElementBorrowed) -> bool;
}
ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.