Skip to content
Permalink
Browse files

Remove the need to destructure InlineFragments

We do this by moving InlineFragmentMap::fixup into InlineFragments
  • Loading branch information
brendanzab committed Jun 2, 2014
1 parent 86efd92 commit 2b23a2ca944d627f06ef39cc696feadf81fbb04b
Showing with 189 additions and 226 deletions.
  1. +5 −66 src/components/main/layout/construct.rs
  2. +178 −144 src/components/main/layout/inline.rs
  3. +6 −16 src/components/main/layout/text.rs
@@ -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 };
}
}

@@ -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,
}
}

0 comments on commit 2b23a2c

Please sign in to comment.
You can’t perform that action at this time.