Skip to content

Commit

Permalink
Remove the need to destructure InlineFragments
Browse files Browse the repository at this point in the history
We do this by moving InlineFragmentMap::fixup into InlineFragments
  • Loading branch information
brendanzab committed Jun 2, 2014
1 parent 86efd92 commit 2b23a2c
Show file tree
Hide file tree
Showing 3 changed files with 189 additions and 226 deletions.
71 changes: 5 additions & 66 deletions src/components/main/layout/construct.rs
Original file line number Diff line number Diff line change
Expand Up @@ -307,23 +307,17 @@ impl<'a> FlowConstructor<'a> {
whitespace_stripping: WhitespaceStrippingMode,
node: &ThreadSafeLayoutNode) {
let mut fragments = fragment_accumulator.finish();
if fragments.len() == 0 {
return
}
if fragments.is_empty() { return };

match whitespace_stripping {
NoWhitespaceStripping => {}
StripWhitespaceFromStart => {
strip_ignorable_whitespace_from_start(&mut fragments);
if fragments.len() == 0 {
return
}
fragments.strip_ignorable_whitespace_from_start();
if fragments.is_empty() { return };
}
StripWhitespaceFromEnd => {
strip_ignorable_whitespace_from_end(&mut fragments);
if fragments.len() == 0 {
return
}
fragments.strip_ignorable_whitespace_from_end();
if fragments.is_empty() { return };
}
}

Expand Down Expand Up @@ -1084,58 +1078,3 @@ impl<'ln> ObjectElement for ThreadSafeLayoutNode<'ln> {
}
}
}

/// Strips ignorable whitespace from the start of a list of fragments.
fn strip_ignorable_whitespace_from_start(fragments: &mut InlineFragments) {
if fragments.len() == 0 {
return
}

let InlineFragments {
fragments: old_fragments,
map: mut map
} = mem::replace(fragments, InlineFragments::new());

// FIXME(#2264, pcwalton): This is slow because vector shift is broken. :(
let mut found_nonwhitespace = false;
let mut new_fragments = Vec::new();
for fragment in old_fragments.iter() {
if !found_nonwhitespace && fragment.is_whitespace_only() {
debug!("stripping ignorable whitespace from start");
continue
}

found_nonwhitespace = true;
new_fragments.push(fragment.clone())
}

map.fixup(old_fragments.as_slice(), new_fragments.as_slice());
*fragments = InlineFragments {
fragments: new_fragments,
map: map,
}
}

/// Strips ignorable whitespace from the end of a list of fragments.
fn strip_ignorable_whitespace_from_end(fragments: &mut InlineFragments) {
if fragments.len() == 0 {
return
}

let InlineFragments {
fragments: old_fragments,
map: mut map
} = mem::replace(fragments, InlineFragments::new());

let mut new_fragments = old_fragments.clone();
while new_fragments.len() > 0 && new_fragments.as_slice().last().get_ref().is_whitespace_only() {
debug!("stripping ignorable whitespace from end");
drop(new_fragments.pop());
}

map.fixup(old_fragments.as_slice(), new_fragments.as_slice());
*fragments = InlineFragments {
fragments: new_fragments,
map: map,
}
}
Loading

0 comments on commit 2b23a2c

Please sign in to comment.