style: Make GetFlattenedTreeParent more straight-forward.

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
This commit is contained in:
Emilio Cobos Álvarez 2017-12-31 20:57:32 +01:00
parent 27a443fbaa
commit 51e2942c25
No known key found for this signature in database
GPG key ID: 056B727BB9C1027C
2 changed files with 17 additions and 9 deletions

View file

@ -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 , ) ; pub fn Gecko_RecordTraversalStatistics ( total : u32 , parallel : u32 , total_t : u32 , parallel_t : u32 , total_s : u32 , parallel_s : u32 , ) ;
} extern "C" { } extern "C" {
pub fn Gecko_IsInDocument ( node : RawGeckoNodeBorrowed , ) -> bool ; pub fn Gecko_IsInDocument ( node : RawGeckoNodeBorrowed , ) -> bool ;
} extern "C" {
pub fn Gecko_FlattenedTreeParentIsParent ( node : RawGeckoNodeBorrowed , ) -> bool ;
} extern "C" { } extern "C" {
pub fn Gecko_IsSignificantChild ( node : RawGeckoNodeBorrowed , text_is_significant : bool , whitespace_is_significant : bool , ) -> bool ; pub fn Gecko_IsSignificantChild ( node : RawGeckoNodeBorrowed , text_is_significant : bool , whitespace_is_significant : bool , ) -> bool ;
} extern "C" { } extern "C" {

View file

@ -236,13 +236,23 @@ impl<'ln> GeckoNode<'ln> {
#[inline] #[inline]
fn flattened_tree_parent(&self) -> Option<Self> { fn flattened_tree_parent(&self) -> Option<Self> {
let fast_path = self.flattened_tree_parent_is_parent(); // TODO(emilio): Measure and consider not doing this fast-path and take
debug_assert!(fast_path == unsafe { bindings::Gecko_FlattenedTreeParentIsParent(self.0) }); // always the common path, it's only a function call and from profiles
if fast_path { // it seems that keeping this fast path makes the compiler not inline
unsafe { self.0.mParent.as_ref().map(GeckoNode) } // `flattened_tree_parent`.
} else { if self.flattened_tree_parent_is_parent() {
unsafe { bindings::Gecko_GetFlattenedTreeParentNode(self.0).map(GeckoNode) } 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] #[inline]