layout: Consolidate passes in the sequential path that were consolidated

in the parallel path.
This commit is contained in:
Patrick Walton 2014-01-30 14:24:15 -08:00
parent 0dd37d9cd3
commit 939f1a28a3
4 changed files with 35 additions and 47 deletions

View file

@ -5,21 +5,27 @@
// High-level interface to CSS selector matching.
use css::node_style::StyledNode;
use layout::extra::LayoutAuxMethods;
use layout::incremental;
use layout::util::LayoutDataAccess;
use layout::wrapper::LayoutNode;
use extra::arc::Arc;
use script::layout_interface::LayoutChan;
use servo_util::smallvec::SmallVec;
use style::{TNode, Stylist, cascade};
use style::{Before, After};
pub trait MatchMethods {
fn match_node(&self, stylist: &Stylist);
fn match_subtree(&self, stylist: &Stylist);
/// Performs aux initialization, selector matching, and cascading sequentially.
fn match_and_cascade_subtree(&self,
stylist: &Stylist,
layout_chan: &LayoutChan,
parent: Option<LayoutNode>);
unsafe fn cascade_node(&self, parent: Option<LayoutNode>);
fn cascade_subtree(&self, parent: Option<LayoutNode>);
}
impl<'ln> MatchMethods for LayoutNode<'ln> {
@ -55,11 +61,22 @@ impl<'ln> MatchMethods for LayoutNode<'ln> {
}
}
fn match_subtree(&self, stylist: &Stylist) {
for node in self.traverse_preorder() {
if node.is_element() {
node.match_node(stylist);
fn match_and_cascade_subtree(&self,
stylist: &Stylist,
layout_chan: &LayoutChan,
parent: Option<LayoutNode>) {
self.initialize_layout_data((*layout_chan).clone());
if self.is_element() {
self.match_node(stylist);
}
unsafe {
self.cascade_node(parent)
}
for kid in self.children() {
kid.match_and_cascade_subtree(stylist, layout_chan, Some(*self))
}
}
@ -132,14 +149,5 @@ impl<'ln> MatchMethods for LayoutNode<'ln> {
}
}
}
fn cascade_subtree(&self, parent: Option<LayoutNode>) {
unsafe {
self.cascade_node(parent);
}
for kid in self.children() {
kid.cascade_subtree(Some(*self));
}
}
}

View file

@ -11,7 +11,6 @@ use css::node_style::StyledNode;
use layout::construct::{FlowConstructionResult, FlowConstructor, NoConstructionResult};
use layout::context::LayoutContext;
use layout::display_list_builder::{DisplayListBuilder, ToGfxColor};
use layout::extra::LayoutAuxMethods;
use layout::flow::{Flow, FlowLeafSet, ImmutableFlowUtils, MutableFlowUtils, MutableOwnedFlowUtils};
use layout::flow::{PreorderFlowTraversal, PostorderFlowTraversal};
use layout::flow;
@ -548,37 +547,24 @@ impl LayoutTask {
let mut layout_root = profile(time::LayoutStyleRecalcCategory,
self.profiler_chan.clone(),
|| {
// Initialize layout data for each node.
//
// FIXME(pcwalton): This is inefficient. We don't need an entire traversal to do this
// in sequential mode!
if self.parallel_traversal.is_none() {
profile(time::LayoutAuxInitCategory, self.profiler_chan.clone(), || {
node.initialize_style_for_subtree(self.chan.clone());
});
}
// Perform CSS selector matching if necessary.
match data.damage.level {
ReflowDocumentDamage => {}
_ => {
profile(time::LayoutSelectorMatchCategory, self.profiler_chan.clone(), || {
match self.parallel_traversal {
None => node.match_subtree(self.stylist),
None => {
node.match_and_cascade_subtree(self.stylist,
&layout_ctx.layout_chan,
None)
}
Some(ref mut traversal) => {
parallel::match_and_cascade_subtree(node, &mut layout_ctx, traversal)
parallel::match_and_cascade_subtree(node,
&mut layout_ctx,
traversal)
}
}
});
// If we're doing layout sequentially, do the cascade separately.
//
// TODO(pcwalton): Integrate this into `match_subtree`.
if self.parallel_traversal.is_none() {
profile(time::LayoutSelectorCascadeCategory, self.profiler_chan.clone(), || {
node.cascade_subtree(None);
});
}
})
}
}

View file

@ -100,7 +100,7 @@ pub mod layout {
pub mod util;
pub mod incremental;
pub mod wrapper;
mod extra;
pub mod extra;
}
pub mod windowing;

View file

@ -51,9 +51,7 @@ pub enum ProfilerCategory {
LayoutQueryCategory,
LayoutPerformCategory,
LayoutStyleRecalcCategory,
LayoutAuxInitCategory,
LayoutSelectorMatchCategory,
LayoutSelectorCascadeCategory,
LayoutTreeBuilderCategory,
LayoutDamagePropagateCategory,
LayoutMainCategory,
@ -81,9 +79,7 @@ impl ProfilerCategory {
buckets.insert(LayoutQueryCategory, ~[]);
buckets.insert(LayoutPerformCategory, ~[]);
buckets.insert(LayoutStyleRecalcCategory, ~[]);
buckets.insert(LayoutAuxInitCategory, ~[]);
buckets.insert(LayoutSelectorMatchCategory, ~[]);
buckets.insert(LayoutSelectorCascadeCategory, ~[]);
buckets.insert(LayoutTreeBuilderCategory, ~[]);
buckets.insert(LayoutMainCategory, ~[]);
buckets.insert(LayoutParallelWarmupCategory, ~[]);
@ -107,8 +103,6 @@ impl ProfilerCategory {
LayoutDispListBuildCategory |
LayoutShapingCategory |
LayoutDamagePropagateCategory => "+ ",
LayoutAuxInitCategory |
LayoutSelectorCascadeCategory |
LayoutParallelWarmupCategory |
LayoutSelectorMatchCategory |
LayoutTreeBuilderCategory => "| + ",