layout: Stop adding flows to the leaf set that are obviously never going

to be leaves.

60% improvement in flow tree construction time on the rainbow page.
This commit is contained in:
Patrick Walton 2014-01-29 13:28:02 -08:00
parent 6c63de1c03
commit e579daefc2
3 changed files with 100 additions and 52 deletions

View file

@ -26,7 +26,7 @@ use layout::box_::{Box, GenericBox, IframeBox, IframeBoxInfo, ImageBox, ImageBox
use layout::box_::{UnscannedTextBox, UnscannedTextBoxInfo, InlineInfo, InlineParentInfo};
use layout::context::LayoutContext;
use layout::float_context::FloatType;
use layout::flow::{BaseFlow, Flow, LeafSet, MutableOwnedFlowUtils};
use layout::flow::{BaseFlow, Flow, ImmutableFlowUtils, LeafSet, MutableOwnedFlowUtils};
use layout::inline::InlineFlow;
use layout::text::TextRunScanner;
use layout::util::{LayoutDataAccess, OpaqueNode};
@ -274,13 +274,10 @@ impl<'fc> FlowConstructor<'fc> {
let inline_base = BaseFlow::new(self.next_flow_id(), node);
let mut inline_flow = ~InlineFlow::from_boxes(inline_base, boxes) as ~Flow;
self.layout_context.leaf_set.access(|leaf_set| leaf_set.insert(&inline_flow));
self.layout_context.leaf_set.access(|leaf_set| inline_flow.mark_as_leaf(leaf_set));
TextRunScanner::new().scan_for_runs(self.font_context, inline_flow);
let mut inline_flow = Some(inline_flow);
self.layout_context.leaf_set.access(|leaf_set| {
flow.add_new_child(inline_flow.take_unwrap(), leaf_set)
})
flow.add_new_child(inline_flow)
}
/// Creates an inline flow from a set of inline boxes, if present, and adds it as a child of
@ -323,10 +320,7 @@ impl<'fc> FlowConstructor<'fc> {
self.flush_inline_boxes_to_flow_if_necessary(&mut opt_boxes_for_inline_flow,
flow,
node);
let mut kid_flow = Some(kid_flow);
self.layout_context.leaf_set.access(|leaf_set| {
flow.add_new_child(kid_flow.take_unwrap(), leaf_set)
})
flow.add_new_child(kid_flow)
}
ConstructionItemConstructionResult(InlineBoxesConstructionItem(
InlineBoxesConstructionResult {
@ -366,10 +360,7 @@ impl<'fc> FlowConstructor<'fc> {
// Push the flow generated by the {ib} split onto our list of
// flows.
let mut kid_flow = Some(kid_flow);
self.layout_context.leaf_set.access(|leaf_set| {
flow.add_new_child(kid_flow.take_unwrap(), leaf_set)
})
flow.add_new_child(kid_flow)
}
}
}
@ -386,6 +377,13 @@ impl<'fc> FlowConstructor<'fc> {
self.flush_inline_boxes_to_flow_if_necessary(&mut opt_boxes_for_inline_flow,
flow,
node);
// The flow is done. If it ended up with no kids, add the flow to the leaf set.
if flow.child_count() == 0 {
self.layout_context.leaf_set.access(|leaf_set| flow.mark_as_leaf(leaf_set))
} else {
flow.mark_as_nonleaf()
}
}
/// Builds a flow for a node with `display: block`. This yields a `BlockFlow` with possibly
@ -395,9 +393,6 @@ impl<'fc> FlowConstructor<'fc> {
let base = BaseFlow::new(self.next_flow_id(), node);
let box_ = self.build_box_for_node(node);
let mut flow = ~BlockFlow::from_box(base, box_, is_fixed) as ~Flow;
self.layout_context.leaf_set.access(|leaf_set| leaf_set.insert(&flow));
self.build_children_of_block_flow(&mut flow, node);
flow
}
@ -410,9 +405,6 @@ impl<'fc> FlowConstructor<'fc> {
let box_ = self.build_box_for_node(node);
let mut flow = ~BlockFlow::float_from_box(base, float_type, box_) as ~Flow;
self.layout_context.leaf_set.access(|leaf_set| leaf_set.insert(&flow));
self.build_children_of_block_flow(&mut flow, node);
flow
}