Auto merge of #19493 - emilio:chrome-perf, r=xidorn,Manishearth

style: Some stylo-chrome perf tweaks.

<!-- Reviewable:start -->
This change is [<img src="https://reviewable.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/servo/19493)
<!-- Reviewable:end -->
This commit is contained in:
bors-servo 2017-12-05 06:05:25 -06:00 committed by GitHub
commit 8f30880d36
4 changed files with 399 additions and 58 deletions

View file

@ -528,14 +528,10 @@ extern "C" {
pub fn Gecko_LoadStyleSheet ( loader : * mut Loader , parent : * mut ServoStyleSheet , reusable_sheets : * mut LoaderReusableStyleSheets , base_url_data : * mut RawGeckoURLExtraData , url_bytes : * const u8 , url_length : u32 , media_list : RawServoMediaListStrong , ) -> * mut ServoStyleSheet ;
} extern "C" {
pub fn Gecko_ElementState ( element : RawGeckoElementBorrowed , ) -> u64 ;
} extern "C" {
pub fn Gecko_DocumentState ( aDocument : * const nsIDocument , ) -> u64 ;
} extern "C" {
pub fn Gecko_IsRootElement ( element : RawGeckoElementBorrowed , ) -> bool ;
} extern "C" {
pub fn Gecko_MatchesElement ( type_ : CSSPseudoClassType , element : RawGeckoElementBorrowed , ) -> bool ;
} extern "C" {
pub fn Gecko_Namespace ( element : RawGeckoElementBorrowed , ) -> * mut nsAtom ;
} extern "C" {
pub fn Gecko_MatchLang ( element : RawGeckoElementBorrowed , override_lang : * mut nsAtom , has_override_lang : bool , value : * const u16 , ) -> bool ;
} extern "C" {
@ -600,8 +596,6 @@ extern "C" {
pub fn Gecko_IsPrivateBrowsingEnabled ( aDoc : * const nsIDocument , ) -> bool ;
} extern "C" {
pub fn Gecko_GetAnimationRule ( aElementOrPseudo : RawGeckoElementBorrowed , aCascadeLevel : EffectCompositor_CascadeLevel , aAnimationValues : RawServoAnimationValueMapBorrowedMut , ) -> bool ;
} extern "C" {
pub fn Gecko_GetSMILOverrideDeclarationBlock ( element : RawGeckoElementBorrowed , ) -> RawServoDeclarationBlockStrongBorrowedOrNull ;
} extern "C" {
pub fn Gecko_StyleAnimationsEquals ( arg1 : RawGeckoStyleAnimationListBorrowed , arg2 : RawGeckoStyleAnimationListBorrowed , ) -> bool ;
} extern "C" {

File diff suppressed because one or more lines are too long

View file

@ -29,9 +29,9 @@ use gecko::selector_parser::{SelectorImpl, NonTSPseudoClass, PseudoElement};
use gecko::snapshot_helpers;
use gecko_bindings::bindings;
use gecko_bindings::bindings::{Gecko_ConstructStyleChildrenIterator, Gecko_DestroyStyleChildrenIterator};
use gecko_bindings::bindings::{Gecko_DocumentState, Gecko_ElementState, Gecko_GetDocumentLWTheme};
use gecko_bindings::bindings::{Gecko_ElementState, Gecko_GetDocumentLWTheme};
use gecko_bindings::bindings::{Gecko_GetLastChild, Gecko_GetNextStyleChild};
use gecko_bindings::bindings::{Gecko_IsRootElement, Gecko_MatchesElement, Gecko_Namespace};
use gecko_bindings::bindings::{Gecko_IsRootElement, Gecko_MatchesElement};
use gecko_bindings::bindings::{Gecko_SetNodeFlags, Gecko_UnsetNodeFlags};
use gecko_bindings::bindings::Gecko_ClassOrClassList;
use gecko_bindings::bindings::Gecko_ElementHasAnimations;
@ -41,7 +41,6 @@ use gecko_bindings::bindings::Gecko_GetActiveLinkAttrDeclarationBlock;
use gecko_bindings::bindings::Gecko_GetAnimationRule;
use gecko_bindings::bindings::Gecko_GetExtraContentStyleDeclarations;
use gecko_bindings::bindings::Gecko_GetHTMLPresentationAttrDeclarationBlock;
use gecko_bindings::bindings::Gecko_GetSMILOverrideDeclarationBlock;
use gecko_bindings::bindings::Gecko_GetStyleAttrDeclarationBlock;
use gecko_bindings::bindings::Gecko_GetUnvisitedLinkAttrDeclarationBlock;
use gecko_bindings::bindings::Gecko_GetVisitedLinkAttrDeclarationBlock;
@ -610,6 +609,7 @@ impl<'le> GeckoElement<'le> {
}
}
#[inline]
fn namespace_id(&self) -> i32 {
self.as_node().node_info().mInner.mNamespaceID
}
@ -658,12 +658,11 @@ impl<'le> GeckoElement<'le> {
unsafe { Gecko_ElementState(self.0) }
}
#[inline]
fn document_state(&self) -> DocumentState {
let node = self.as_node();
unsafe {
let states = Gecko_DocumentState(node.owner_doc().0);
DocumentState::from_bits_truncate(states)
}
DocumentState::from_bits_truncate(
self.as_node().owner_doc().0.mDocumentState.mStates
)
}
#[inline]
@ -1054,14 +1053,43 @@ impl<'le> TElement for GeckoElement<'le> {
}
fn get_smil_override(&self) -> Option<ArcBorrow<Locked<PropertyDeclarationBlock>>> {
let declarations = unsafe { Gecko_GetSMILOverrideDeclarationBlock(self.0) };
let declarations: Option<&RawOffsetArc<Locked<PropertyDeclarationBlock>>> =
declarations.and_then(|s| s.as_arc_opt());
declarations.map(|s| s.borrow_arc())
unsafe {
let slots = match self.get_extended_slots() {
Some(s) => s,
None => return None,
};
let base_declaration: &structs::DeclarationBlock =
match slots.mSMILOverrideStyleDeclaration.mRawPtr.as_ref() {
Some(decl) => decl,
None => return None,
};
assert_eq!(base_declaration.mType, structs::StyleBackendType_Servo);
let declaration: &structs::ServoDeclarationBlock =
mem::transmute(base_declaration);
debug_assert_eq!(
&declaration._base as *const structs::DeclarationBlock,
base_declaration as *const structs::DeclarationBlock
);
let raw: &structs::RawServoDeclarationBlock =
match declaration.mRaw.mRawPtr.as_ref() {
Some(decl) => decl,
None => return None,
};
Some(Locked::<PropertyDeclarationBlock>::as_arc(
&*(&raw as *const &structs::RawServoDeclarationBlock)
).borrow_arc())
}
}
fn get_animation_rule_by_cascade(&self, cascade_level: ServoCascadeLevel)
-> Option<Arc<Locked<PropertyDeclarationBlock>>> {
fn get_animation_rule_by_cascade(
&self,
cascade_level: ServoCascadeLevel,
) -> Option<Arc<Locked<PropertyDeclarationBlock>>> {
match cascade_level {
ServoCascadeLevel::Animations => self.get_animation_rule(),
ServoCascadeLevel::Transitions => self.get_transition_rule(),
@ -1940,7 +1968,8 @@ impl<'le> ::selectors::Element for GeckoElement<'le> {
#[inline]
fn get_namespace(&self) -> &WeakNamespace {
unsafe {
WeakNamespace::new(Gecko_Namespace(self.0))
let namespace_manager = structs::nsContentUtils_sNameSpaceManager;
WeakNamespace::new((*namespace_manager).mURIArray[self.namespace_id() as usize].mRawPtr)
}
}

View file

@ -12,12 +12,14 @@ use dom::TElement;
use selectors::NthIndexCache;
use sharing::{StyleSharingCandidate, StyleSharingTarget};
/// Determines whether a target and a candidate have compatible parents for sharing.
/// Determines whether a target and a candidate have compatible parents for
/// sharing.
pub fn parents_allow_sharing<E>(
target: &mut StyleSharingTarget<E>,
candidate: &mut StyleSharingCandidate<E>
) -> bool
where E: TElement,
where
E: TElement,
{
// If the identity of the parent style isn't equal, we can't share. We check
// this first, because the result is cached.
@ -58,7 +60,8 @@ pub fn have_same_style_attribute<E>(
target: &mut StyleSharingTarget<E>,
candidate: &mut StyleSharingCandidate<E>
) -> bool
where E: TElement,
where
E: TElement,
{
match (target.style_attribute(), candidate.style_attribute()) {
(None, None) => true,
@ -72,7 +75,8 @@ pub fn have_same_presentational_hints<E>(
target: &mut StyleSharingTarget<E>,
candidate: &mut StyleSharingCandidate<E>
) -> bool
where E: TElement,
where
E: TElement,
{
target.pres_hints() == candidate.pres_hints()
}
@ -80,10 +84,12 @@ pub fn have_same_presentational_hints<E>(
/// Whether a given element has the same class attribute than a given candidate.
///
/// We don't try to share style across elements with different class attributes.
pub fn have_same_class<E>(target: &mut StyleSharingTarget<E>,
candidate: &mut StyleSharingCandidate<E>)
-> bool
where E: TElement,
pub fn have_same_class<E>(
target: &mut StyleSharingTarget<E>,
candidate: &mut StyleSharingCandidate<E>,
) -> bool
where
E: TElement,
{
target.class_list() == candidate.class_list()
}