Skip to content

Commit

Permalink
layout: Stop adding damage when removing whitespace.
Browse files Browse the repository at this point in the history
Avoids total reflow of the entire document on the maze solver.
  • Loading branch information
pcwalton committed Oct 28, 2014
1 parent 3aad350 commit 01965c3
Showing 1 changed file with 6 additions and 18 deletions.
24 changes: 6 additions & 18 deletions components/layout/construct.rs
Expand Up @@ -306,15 +306,13 @@ impl<'a> FlowConstructor<'a> {
match whitespace_stripping {
NoWhitespaceStripping => {}
StripWhitespaceFromStart => {
flow::mut_base(flow.deref_mut()).restyle_damage.insert(
strip_ignorable_whitespace_from_start(&mut fragments));
strip_ignorable_whitespace_from_start(&mut fragments);
if fragments.is_empty() {
return
};
}
StripWhitespaceFromEnd => {
flow::mut_base(flow.deref_mut()).restyle_damage.insert(
strip_ignorable_whitespace_from_end(&mut fragments));
strip_ignorable_whitespace_from_end(&mut fragments);
if fragments.is_empty() {
return
};
Expand Down Expand Up @@ -1232,36 +1230,26 @@ impl FlowConstructionUtils for FlowRef {
}

/// Strips ignorable whitespace from the start of a list of fragments.
///
/// Returns some damage that must be added to the `InlineFlow`.
pub fn strip_ignorable_whitespace_from_start(this: &mut DList<Fragment>) -> RestyleDamage {
pub fn strip_ignorable_whitespace_from_start(this: &mut DList<Fragment>) {
if this.is_empty() {
return RestyleDamage::empty() // Fast path.
return // Fast path.
}

let mut damage = RestyleDamage::empty();
while !this.is_empty() && this.front().as_ref().unwrap().is_ignorable_whitespace() {
debug!("stripping ignorable whitespace from start");
damage = RestyleDamage::all();
drop(this.pop_front());
}
damage
}

/// Strips ignorable whitespace from the end of a list of fragments.
///
/// Returns some damage that must be added to the `InlineFlow`.
pub fn strip_ignorable_whitespace_from_end(this: &mut DList<Fragment>) -> RestyleDamage {
pub fn strip_ignorable_whitespace_from_end(this: &mut DList<Fragment>) {
if this.is_empty() {
return RestyleDamage::empty();
return
}

let mut damage = RestyleDamage::empty();
while !this.is_empty() && this.back().as_ref().unwrap().is_ignorable_whitespace() {
debug!("stripping ignorable whitespace from end");
damage = RestyleDamage::all();
drop(this.pop());
}
damage
}

5 comments on commit 01965c3

@bors-servo
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

saw approval from cgaebel
at pcwalton@01965c3

@bors-servo
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

merging pcwalton/servo/removing-whitespace-damage = 01965c3 into auto

@bors-servo
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

pcwalton/servo/removing-whitespace-damage = 01965c3 merged ok, testing candidate = c20bb66

@bors-servo
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@bors-servo
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fast-forwarding master to auto = c20bb66

Please sign in to comment.