servo: Merge #19673 - style: Make GetFlattenedTreeParent more straight-forward (from emilio:flattened-tree-parent); r=smaug

Now that accessing nsIContent slots is not a blob of virtual function calls, we
should be able to unify logic here, and speed up the not-so-rare case for
chrome, while keeping the usual case fast.

Bug: 1427511
Reviewed-by: smaug
MozReview-Commit-ID: 87iY5Cbhx4T
Source-Repo: https://github.com/servo/servo
Source-Revision: 9187c9a093860d9f3c31b5a5f402458aa4a607cb

--HG--
extra : subtree_source : https%3A//hg.mozilla.org/projects/converted-servo-linear
extra : subtree_revision : 246fcb20110ef1096cf79d73a3b2985ea15aa466
This commit is contained in:
Emilio Cobos Álvarez 2018-01-02 10:00:22 -06:00
Родитель 92b150e06c
Коммит 71ed50bebd
2 изменённых файлов: 17 добавлений и 9 удалений

Просмотреть файл

@ -503,8 +503,6 @@ extern "C" {
pub fn Gecko_RecordTraversalStatistics ( total : u32 , parallel : u32 , total_t : u32 , parallel_t : u32 , total_s : u32 , parallel_s : u32 , ) ;
} extern "C" {
pub fn Gecko_IsInDocument ( node : RawGeckoNodeBorrowed , ) -> bool ;
} extern "C" {
pub fn Gecko_FlattenedTreeParentIsParent ( node : RawGeckoNodeBorrowed , ) -> bool ;
} extern "C" {
pub fn Gecko_IsSignificantChild ( node : RawGeckoNodeBorrowed , text_is_significant : bool , whitespace_is_significant : bool , ) -> bool ;
} extern "C" {
@ -1599,4 +1597,4 @@ extern "C" {
pub fn Gecko_GetElementsWithId ( aDocument : * const nsIDocument , aId : * mut nsAtom , ) -> * const nsTArray < * mut Element > ;
} extern "C" {
pub fn Gecko_GetBoolPrefValue ( pref_name : * const :: std :: os :: raw :: c_char , ) -> bool ;
}
}

Просмотреть файл

@ -236,13 +236,23 @@ impl<'ln> GeckoNode<'ln> {
#[inline]
fn flattened_tree_parent(&self) -> Option<Self> {
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_GetFlattenedTreeParentNode(self.0).map(GeckoNode) }
// TODO(emilio): Measure and consider not doing this fast-path and take
// always the common path, it's only a function call and from profiles
// it seems that keeping this fast path makes the compiler not inline
// `flattened_tree_parent`.
if self.flattened_tree_parent_is_parent() {
debug_assert_eq!(
unsafe { bindings::Gecko_GetFlattenedTreeParentNode(self.0).map(GeckoNode) },
self.parent_node(),
"Fast path stopped holding!"
);
return self.parent_node();
}
// NOTE(emilio): If this call is too expensive, we could manually
// inline more aggressively.
unsafe { bindings::Gecko_GetFlattenedTreeParentNode(self.0).map(GeckoNode) }
}
#[inline]