diff --git a/src/components/main/css/matching.rs b/src/components/main/css/matching.rs index ec82ee17c0f..62e805a1745 100644 --- a/src/components/main/css/matching.rs +++ b/src/components/main/css/matching.rs @@ -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); unsafe fn cascade_node(&self, parent: Option); - fn cascade_subtree(&self, parent: Option); } 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) { + 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) { - unsafe { - self.cascade_node(parent); - } - - for kid in self.children() { - kid.cascade_subtree(Some(*self)); - } - } } + diff --git a/src/components/main/layout/layout_task.rs b/src/components/main/layout/layout_task.rs index 28a19b657be..8b2b7d72fb5 100644 --- a/src/components/main/layout/layout_task.rs +++ b/src/components/main/layout/layout_task.rs @@ -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); - }); - } + }) } } diff --git a/src/components/main/servo.rc b/src/components/main/servo.rc index 342aacae57f..b92f29893fc 100755 --- a/src/components/main/servo.rc +++ b/src/components/main/servo.rc @@ -100,7 +100,7 @@ pub mod layout { pub mod util; pub mod incremental; pub mod wrapper; - mod extra; + pub mod extra; } pub mod windowing; diff --git a/src/components/util/time.rs b/src/components/util/time.rs index 049cc64e9f0..4a5095eb33c 100644 --- a/src/components/util/time.rs +++ b/src/components/util/time.rs @@ -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 => "| + ",