style: Cleanup invalidation processor constructor.

It used to be this way because of lifetime issues (plus the shadow
datas were in RwLocks at some point IIRC). Now we guarantee that as long as the
element is away the cascade data is as well, so we don't need to thread it
around.

Differential Revision: https://phabricator.services.mozilla.com/D2768
This commit is contained in:
Emilio Cobos Álvarez 2018-08-07 10:36:18 +00:00
parent bbcd7e414a
commit 0ae47b2659
No known key found for this signature in database
GPG key ID: 056B727BB9C1027C
2 changed files with 12 additions and 21 deletions

View file

@ -16,7 +16,6 @@ use selector_parser::{PseudoElement, RestyleDamage, EAGER_PSEUDO_COUNT};
use selectors::NthIndexCache; use selectors::NthIndexCache;
use servo_arc::Arc; use servo_arc::Arc;
use shared_lock::StylesheetGuards; use shared_lock::StylesheetGuards;
use smallvec::SmallVec;
use std::fmt; use std::fmt;
use std::mem; use std::mem;
use std::ops::{Deref, DerefMut}; use std::ops::{Deref, DerefMut};
@ -273,16 +272,8 @@ impl ElementData {
return InvalidationResult::empty(); return InvalidationResult::empty();
} }
let mut non_document_styles = SmallVec::<[_; 3]>::new();
let matches_doc_author_rules =
element.each_applicable_non_document_style_rule_data(|data, quirks_mode, host| {
non_document_styles.push((data, quirks_mode, host.map(|h| h.opaque())))
});
let mut processor = StateAndAttrInvalidationProcessor::new( let mut processor = StateAndAttrInvalidationProcessor::new(
shared_context, shared_context,
&non_document_styles,
matches_doc_author_rules,
element, element,
self, self,
nth_index_cache, nth_index_cache,

View file

@ -6,7 +6,7 @@
//! changes. //! changes.
use {Atom, WeakAtom}; use {Atom, WeakAtom};
use context::{QuirksMode, SharedStyleContext}; use context::SharedStyleContext;
use data::ElementData; use data::ElementData;
use dom::TElement; use dom::TElement;
use element_state::ElementState; use element_state::ElementState;
@ -18,13 +18,11 @@ use invalidation::element::restyle_hints::RestyleHint;
use selector_map::SelectorMap; use selector_map::SelectorMap;
use selector_parser::Snapshot; use selector_parser::Snapshot;
use selectors::NthIndexCache; use selectors::NthIndexCache;
use selectors::OpaqueElement;
use selectors::attr::CaseSensitivity; use selectors::attr::CaseSensitivity;
use selectors::matching::{MatchingContext, MatchingMode, VisitedHandlingMode}; use selectors::matching::{MatchingContext, MatchingMode, VisitedHandlingMode};
use selectors::matching::matches_selector; use selectors::matching::matches_selector;
use smallvec::SmallVec; use smallvec::SmallVec;
use stylesheets::origin::{Origin, OriginSet}; use stylesheets::origin::{Origin, OriginSet};
use stylist::CascadeData;
#[derive(Debug, PartialEq)] #[derive(Debug, PartialEq)]
enum VisitedDependent { enum VisitedDependent {
@ -56,19 +54,15 @@ where
/// changes. /// changes.
pub struct StateAndAttrInvalidationProcessor<'a, 'b: 'a, E: TElement> { pub struct StateAndAttrInvalidationProcessor<'a, 'b: 'a, E: TElement> {
shared_context: &'a SharedStyleContext<'b>, shared_context: &'a SharedStyleContext<'b>,
shadow_rule_datas: &'a [(&'b CascadeData, QuirksMode, Option<OpaqueElement>)],
matches_document_author_rules: bool,
element: E, element: E,
data: &'a mut ElementData, data: &'a mut ElementData,
matching_context: MatchingContext<'a, E::Impl>, matching_context: MatchingContext<'a, E::Impl>,
} }
impl<'a, 'b: 'a, E: TElement> StateAndAttrInvalidationProcessor<'a, 'b, E> { impl<'a, 'b: 'a, E: TElement + 'b> StateAndAttrInvalidationProcessor<'a, 'b, E> {
/// Creates a new StateAndAttrInvalidationProcessor. /// Creates a new StateAndAttrInvalidationProcessor.
pub fn new( pub fn new(
shared_context: &'a SharedStyleContext<'b>, shared_context: &'a SharedStyleContext<'b>,
shadow_rule_datas: &'a [(&'b CascadeData, QuirksMode, Option<OpaqueElement>)],
matches_document_author_rules: bool,
element: E, element: E,
data: &'a mut ElementData, data: &'a mut ElementData,
nth_index_cache: &'a mut NthIndexCache, nth_index_cache: &'a mut NthIndexCache,
@ -83,8 +77,6 @@ impl<'a, 'b: 'a, E: TElement> StateAndAttrInvalidationProcessor<'a, 'b, E> {
Self { Self {
shared_context, shared_context,
shadow_rule_datas,
matches_document_author_rules,
element, element,
data, data,
matching_context, matching_context,
@ -157,6 +149,7 @@ where
descendant_invalidations: &mut DescendantInvalidationLists<'a>, descendant_invalidations: &mut DescendantInvalidationLists<'a>,
sibling_invalidations: &mut InvalidationVector<'a>, sibling_invalidations: &mut InvalidationVector<'a>,
) -> bool { ) -> bool {
debug_assert_eq!(element, self.element);
debug_assert!(element.has_snapshot(), "Why bothering?"); debug_assert!(element.has_snapshot(), "Why bothering?");
let wrapper = ElementWrapper::new(element, &*self.shared_context.snapshot_map); let wrapper = ElementWrapper::new(element, &*self.shared_context.snapshot_map);
@ -241,6 +234,13 @@ where
element element
}; };
let mut shadow_rule_datas = SmallVec::<[_; 3]>::new();
let matches_document_author_rules =
element.each_applicable_non_document_style_rule_data(|data, quirks_mode, host| {
shadow_rule_datas.push((data, quirks_mode, host.map(|h| h.opaque())))
});
let invalidated_self = { let invalidated_self = {
let mut collector = Collector { let mut collector = Collector {
wrapper, wrapper,
@ -258,7 +258,7 @@ where
invalidates_self: false, invalidates_self: false,
}; };
let document_origins = if !self.matches_document_author_rules { let document_origins = if !matches_document_author_rules {
Origin::UserAgent.into() Origin::UserAgent.into()
} else { } else {
OriginSet::all() OriginSet::all()
@ -271,7 +271,7 @@ where
} }
} }
for &(ref data, quirks_mode, ref host) in self.shadow_rule_datas { for &(ref data, quirks_mode, ref host) in &shadow_rule_datas {
// FIXME(emilio): Replace with assert / remove when we figure // FIXME(emilio): Replace with assert / remove when we figure
// out what to do with the quirks mode mismatches // out what to do with the quirks mode mismatches
// (that is, when bug 1406875 is properly fixed). // (that is, when bug 1406875 is properly fixed).