Skip to content

Commit

Permalink
auto merge of #3772 : pcwalton/servo/slim-down-fragment, r=metajack
Browse files Browse the repository at this point in the history
16% performance improvement in layout (!)

r? @metajack (or whoever)
  • Loading branch information
bors-servo committed Oct 23, 2014
2 parents 43b13e7 + de5e2fd commit 012a80c
Show file tree
Hide file tree
Showing 8 changed files with 128 additions and 88 deletions.
14 changes: 7 additions & 7 deletions components/layout/construct.rs
Expand Up @@ -238,12 +238,12 @@ impl<'a> FlowConstructor<'a> {
Some(url) => {
// FIXME(pcwalton): The fact that image fragments store the cache within them makes
// little sense to me.
ImageFragment(ImageFragmentInfo::new(node,
url,
self.layout_context
.shared
.image_cache
.clone()))
ImageFragment(box ImageFragmentInfo::new(node,
url,
self.layout_context
.shared
.image_cache
.clone()))
}
}
}
Expand All @@ -258,7 +258,7 @@ impl<'a> FlowConstructor<'a> {
-> SpecificFragmentInfo {
match node.type_id() {
Some(ElementNodeTypeId(HTMLIFrameElementTypeId)) => {
IframeFragment(IframeFragmentInfo::new(node))
IframeFragment(box IframeFragmentInfo::new(node))
}
Some(ElementNodeTypeId(HTMLImageElementTypeId)) => {
self.build_fragment_info_for_image(node, node.image_url())
Expand Down
4 changes: 2 additions & 2 deletions components/layout/display_list_builder.rs
Expand Up @@ -502,7 +502,7 @@ impl FragmentDisplayListBuilding for Fragment {
if opts::get().show_debug_fragment_borders {
self.build_debug_borders_around_text_fragments(display_list,
flow_origin,
text_fragment,
&**text_fragment,
clip_rect);
}
}
Expand Down Expand Up @@ -559,7 +559,7 @@ impl FragmentDisplayListBuilding for Fragment {
// the iframe is actually going to be displayed.
match self.specific {
IframeFragment(ref iframe_fragment) => {
self.finalize_position_and_size_of_iframe(iframe_fragment,
self.finalize_position_and_size_of_iframe(&**iframe_fragment,
absolute_fragment_bounds.origin,
layout_context)
}
Expand Down
142 changes: 88 additions & 54 deletions components/layout/fragment.rs

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion components/layout/incremental.rs
Expand Up @@ -8,7 +8,7 @@ use style::ComputedValues;

bitflags! {
#[doc = "Individual layout actions that may be necessary after restyling."]
flags RestyleDamage: int {
flags RestyleDamage: u8 {
#[doc = "Repaint the node itself."]
#[doc = "Currently unused; need to decide how this propagates."]
static Repaint = 0x01,
Expand Down
34 changes: 19 additions & 15 deletions components/layout/inline.rs
Expand Up @@ -391,7 +391,11 @@ impl LineBreaker {
}

fn try_append_to_line_by_new_line(&mut self, in_fragment: Fragment) -> bool {
if in_fragment.new_line_pos.len() == 0 {
let no_newline_positions = match in_fragment.newline_positions() {
None => true,
Some(ref positions) => positions.is_empty(),
};
if no_newline_positions {
debug!("LineBreaker: Did not find a new-line character, so pushing the fragment to \
the line without splitting.");
self.push_fragment_to_line(in_fragment);
Expand All @@ -406,28 +410,29 @@ impl LineBreaker {
let writing_mode = self.floats.writing_mode;

let split_fragment = |split: SplitInfo| {
let info =
ScannedTextFragmentInfo::new(
run.clone(),
split.range,
in_fragment.border_box.size);
let size = LogicalSize::new(
writing_mode, split.inline_size, in_fragment.border_box.size.block);
let info = box ScannedTextFragmentInfo::new(run.clone(),
split.range,
(*in_fragment.newline_positions()
.unwrap()).clone(),
in_fragment.border_box.size);
let size = LogicalSize::new(writing_mode,
split.inline_size,
in_fragment.border_box.size.block);
in_fragment.transform(size, info)
};

debug!("LineBreaker: Pushing the fragment to the inline_start of the new-line character \
to the line.");
let mut inline_start = split_fragment(inline_start);
inline_start.save_new_line_pos();
inline_start.new_line_pos = vec![];
*inline_start.newline_positions_mut().unwrap() = vec![];
self.push_fragment_to_line(inline_start);

for inline_end in inline_end.into_iter() {
debug!("LineBreaker: Deferring the fragment to the inline_end of the new-line \
character to the line.");
let mut inline_end = split_fragment(inline_end);
inline_end.new_line_pos.remove(0);
inline_end.newline_positions_mut().unwrap().remove(0);
self.work_list.push_front(inline_end);
}

Expand Down Expand Up @@ -497,11 +502,10 @@ impl LineBreaker {
line_is_empty);
match split.map(|(inline_start, inline_end, run)| {
let split_fragment = |split: SplitInfo| {
let info =
ScannedTextFragmentInfo::new(
run.clone(),
split.range,
in_fragment.border_box.size);
let info = box ScannedTextFragmentInfo::new(run.clone(),
split.range,
Vec::new(),
in_fragment.border_box.size);
let size = LogicalSize::new(self.floats.writing_mode,
split.inline_size,
in_fragment.border_box.size.block);
Expand Down
4 changes: 2 additions & 2 deletions components/layout/layout_debug.rs
Expand Up @@ -92,8 +92,8 @@ impl Drop for Scope {
/// Generate a unique ID. This is used for items such as Fragment
/// which are often reallocated but represent essentially the
/// same data.
pub fn generate_unique_debug_id() -> uint {
unsafe { DEBUG_ID_COUNTER.fetch_add(1, SeqCst) }
pub fn generate_unique_debug_id() -> u16 {
unsafe { DEBUG_ID_COUNTER.fetch_add(1, SeqCst) as u16 }
}

/// Begin a layout debug trace. If this has not been called,
Expand Down
3 changes: 2 additions & 1 deletion components/layout/table_colgroup.rs
Expand Up @@ -13,6 +13,7 @@ use layout_debug;
use wrapper::ThreadSafeLayoutNode;

use servo_util::geometry::Au;
use std::cmp::max;
use std::fmt;
use style::computed_values::LengthOrPercentageOrAuto;

Expand Down Expand Up @@ -64,7 +65,7 @@ impl Flow for TableColGroupFlow {
// Retrieve the specified value from the appropriate CSS property.
let inline_size = fragment.style().content_inline_size();
let span: int = match fragment.specific {
TableColumnFragment(col_fragment) => col_fragment.span.unwrap_or(1),
TableColumnFragment(col_fragment) => max(col_fragment.span, 1),
_ => fail!("non-table-column fragment inside table column?!"),
};
for _ in range(0, span) {
Expand Down
13 changes: 7 additions & 6 deletions components/layout/text.rs
Expand Up @@ -160,16 +160,17 @@ impl TextRunScanner {
}

let text_size = old_fragment.border_box.size;
let &NewLinePositions(ref mut new_line_positions) =
new_line_positions.get_mut(logical_offset);
let new_text_fragment_info =
ScannedTextFragmentInfo::new(run.clone(), range, text_size);
box ScannedTextFragmentInfo::new(run.clone(),
range,
mem::replace(new_line_positions, Vec::new()),
text_size);
let new_metrics = new_text_fragment_info.run.metrics_for_range(&range);
let bounding_box_size = bounding_box_for_run_metrics(&new_metrics,
old_fragment.style.writing_mode);
let mut new_fragment = old_fragment.transform(bounding_box_size,
new_text_fragment_info);
let &NewLinePositions(ref mut new_line_positions) =
new_line_positions.get_mut(logical_offset);
new_fragment.new_line_pos = mem::replace(new_line_positions, Vec::new());
let new_fragment = old_fragment.transform(bounding_box_size, new_text_fragment_info);
out_fragments.push(new_fragment)
}

Expand Down

0 comments on commit 012a80c

Please sign in to comment.