Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Move match and cascade temporaries to CurrentElementInfo
Before this change, the `ComputedStyle` struct that is part of permanent style
data per element holds 2 `StrongRuleNode`s (unvisited and visited) and 2
`Arc<ComputedValues>` (unvisited and visited).

Both rule nodes and the visited values don't actually need to be here.  This
patch moves these 3 to new temporary storage in `CascadeInputs` on
`CurrentElementInfo` during the match and cascade process.  Rule nodes are
pushed down inside the `ComputedValues` for later access after the cascade.
(Visited values were already available there.)

The permanent style data per element now has just the `Arc<ComputedValues>` for
itself and eager pseudo-elements (plus the `RestyleHint`).

MozReview-Commit-ID: 3wq52ERMpdi
  • Loading branch information
jryans committed Jun 22, 2017
1 parent c3b2a2f commit 2b5c56e
Show file tree
Hide file tree
Showing 19 changed files with 699 additions and 707 deletions.
2 changes: 1 addition & 1 deletion components/script/layout_wrapper.rs
Expand Up @@ -902,7 +902,7 @@ impl<'ln> ThreadSafeLayoutNode for ServoThreadSafeLayoutNode<'ln> {
fn parent_style(&self) -> Arc<ComputedValues> {
let parent = self.node.parent_node().unwrap().as_element().unwrap();
let parent_data = parent.get_data().unwrap().borrow();
parent_data.styles().primary.values().clone()
parent_data.styles.primary().clone()
}

fn debug_id(self) -> usize {
Expand Down
2 changes: 1 addition & 1 deletion components/script_layout_interface/lib.rs
Expand Up @@ -65,7 +65,7 @@ pub struct StyleData {
impl StyleData {
pub fn new() -> Self {
Self {
element_data: AtomicRefCell::new(ElementData::new(None)),
element_data: AtomicRefCell::new(ElementData::default()),
parallel: DomParallelInfo::new(),
}
}
Expand Down
30 changes: 15 additions & 15 deletions components/script_layout_interface/wrapper_traits.rs
Expand Up @@ -346,7 +346,7 @@ pub trait ThreadSafeLayoutElement: Clone + Copy + Sized + Debug +

#[inline]
fn get_before_pseudo(&self) -> Option<Self> {
if self.style_data().styles().pseudos.has(&PseudoElement::Before) {
if self.style_data().styles.pseudos.has(&PseudoElement::Before) {
Some(self.with_pseudo(PseudoElementType::Before(None)))
} else {
None
Expand All @@ -355,7 +355,7 @@ pub trait ThreadSafeLayoutElement: Clone + Copy + Sized + Debug +

#[inline]
fn get_after_pseudo(&self) -> Option<Self> {
if self.style_data().styles().pseudos.has(&PseudoElement::After) {
if self.style_data().styles.pseudos.has(&PseudoElement::After) {
Some(self.with_pseudo(PseudoElementType::After(None)))
} else {
None
Expand Down Expand Up @@ -396,7 +396,7 @@ pub trait ThreadSafeLayoutElement: Clone + Copy + Sized + Debug +
let data = self.style_data();
match self.get_pseudo_element_type() {
PseudoElementType::Normal => {
data.styles().primary.values().clone()
data.styles.primary().clone()
},
other => {
// Precompute non-eagerly-cascaded pseudo-element styles if not
Expand All @@ -406,17 +406,17 @@ pub trait ThreadSafeLayoutElement: Clone + Copy + Sized + Debug +
// Already computed during the cascade.
PseudoElementCascadeType::Eager => {
self.style_data()
.styles().pseudos.get(&style_pseudo)
.unwrap().values().clone()
.styles.pseudos.get(&style_pseudo)
.unwrap().clone()
},
PseudoElementCascadeType::Precomputed => {
context.stylist.precomputed_values_for_pseudo(
&context.guards,
&style_pseudo,
Some(data.styles().primary.values()),
Some(data.styles.primary()),
CascadeFlags::empty(),
&ServoMetricsProvider)
.values().clone()
.clone()
}
PseudoElementCascadeType::Lazy => {
context.stylist
Expand All @@ -425,10 +425,10 @@ pub trait ThreadSafeLayoutElement: Clone + Copy + Sized + Debug +
unsafe { &self.unsafe_get() },
&style_pseudo,
RuleInclusion::All,
data.styles().primary.values(),
data.styles.primary(),
&ServoMetricsProvider)
.unwrap()
.values().clone()
.clone()
}
}
}
Expand All @@ -438,10 +438,10 @@ pub trait ThreadSafeLayoutElement: Clone + Copy + Sized + Debug +
#[inline]
fn selected_style(&self) -> Arc<ServoComputedValues> {
let data = self.style_data();
data.styles().pseudos
data.styles.pseudos
.get(&PseudoElement::Selection).map(|s| s)
.unwrap_or(&data.styles().primary)
.values().clone()
.unwrap_or(data.styles.primary())
.clone()
}

/// Returns the already resolved style of the node.
Expand All @@ -456,10 +456,10 @@ pub trait ThreadSafeLayoutElement: Clone + Copy + Sized + Debug +
let data = self.style_data();
match self.get_pseudo_element_type() {
PseudoElementType::Normal
=> data.styles().primary.values().clone(),
=> data.styles.primary().clone(),
other
=> data.styles().pseudos
.get(&other.style_pseudo_element()).unwrap().values().clone(),
=> data.styles.pseudos
.get(&other.style_pseudo_element()).unwrap().clone(),
}
}
}
1 change: 1 addition & 0 deletions components/style/animation.rs
Expand Up @@ -502,6 +502,7 @@ fn compute_style_for_animation_step(context: &SharedStyleContext,
// as existing browsers don't appear to animate visited styles.
let computed =
properties::apply_declarations(context.stylist.device(),
previous_style.rules(),
iter,
previous_style,
previous_style,
Expand Down

0 comments on commit 2b5c56e

Please sign in to comment.