Put UnscannedTextFragmentInfo in a Box

This reduces the size of the SpecificFragmentInfo enum from 48 to 24.
This commit is contained in:
Matt Brubeck 2016-03-28 22:03:25 -07:00
parent 14e945f09a
commit 31261f045e
5 changed files with 14 additions and 13 deletions

View file

@ -578,7 +578,7 @@ impl<'a, ConcreteThreadSafeLayoutNode: ThreadSafeLayoutNode>
// Add whitespace results. They will be stripped out later on when // Add whitespace results. They will be stripped out later on when
// between block elements, and retained when between inline elements. // between block elements, and retained when between inline elements.
let fragment_info = SpecificFragmentInfo::UnscannedText( let fragment_info = SpecificFragmentInfo::UnscannedText(
UnscannedTextFragmentInfo::new(" ".to_owned(), None)); box UnscannedTextFragmentInfo::new(" ".to_owned(), None));
properties::modify_style_for_replaced_content(&mut whitespace_style); properties::modify_style_for_replaced_content(&mut whitespace_style);
properties::modify_style_for_text(&mut whitespace_style); properties::modify_style_for_text(&mut whitespace_style);
let fragment = Fragment::from_opaque_node_and_style(whitespace_node, let fragment = Fragment::from_opaque_node_and_style(whitespace_node,
@ -715,7 +715,7 @@ impl<'a, ConcreteThreadSafeLayoutNode: ThreadSafeLayoutNode>
match text_content { match text_content {
TextContent::Text(string) => { TextContent::Text(string) => {
let info = UnscannedTextFragmentInfo::new(string, selection); let info = box UnscannedTextFragmentInfo::new(string, selection);
let specific_fragment_info = SpecificFragmentInfo::UnscannedText(info); let specific_fragment_info = SpecificFragmentInfo::UnscannedText(info);
fragments.fragments.push_back(Fragment::from_opaque_node_and_style( fragments.fragments.push_back(Fragment::from_opaque_node_and_style(
node.opaque(), node.opaque(),
@ -728,7 +728,7 @@ impl<'a, ConcreteThreadSafeLayoutNode: ThreadSafeLayoutNode>
for content_item in content_items.into_iter() { for content_item in content_items.into_iter() {
let specific_fragment_info = match content_item { let specific_fragment_info = match content_item {
ContentItem::String(string) => { ContentItem::String(string) => {
let info = UnscannedTextFragmentInfo::new(string, None); let info = box UnscannedTextFragmentInfo::new(string, None);
SpecificFragmentInfo::UnscannedText(info) SpecificFragmentInfo::UnscannedText(info)
} }
content_item => { content_item => {
@ -859,7 +859,7 @@ impl<'a, ConcreteThreadSafeLayoutNode: ThreadSafeLayoutNode>
whitespace_damage)) => { whitespace_damage)) => {
// Instantiate the whitespace fragment. // Instantiate the whitespace fragment.
let fragment_info = SpecificFragmentInfo::UnscannedText( let fragment_info = SpecificFragmentInfo::UnscannedText(
UnscannedTextFragmentInfo::new(" ".to_owned(), None)); box UnscannedTextFragmentInfo::new(" ".to_owned(), None));
properties::modify_style_for_replaced_content(&mut whitespace_style); properties::modify_style_for_replaced_content(&mut whitespace_style);
properties::modify_style_for_text(&mut whitespace_style); properties::modify_style_for_text(&mut whitespace_style);
let fragment = Fragment::from_opaque_node_and_style(whitespace_node, let fragment = Fragment::from_opaque_node_and_style(whitespace_node,
@ -1241,7 +1241,7 @@ impl<'a, ConcreteThreadSafeLayoutNode: ThreadSafeLayoutNode>
unscanned_marker_fragments.push_back(Fragment::new( unscanned_marker_fragments.push_back(Fragment::new(
node, node,
SpecificFragmentInfo::UnscannedText( SpecificFragmentInfo::UnscannedText(
UnscannedTextFragmentInfo::new(text, None)))); box UnscannedTextFragmentInfo::new(text, None))));
let marker_fragments = TextRunScanner::new().scan_for_runs( let marker_fragments = TextRunScanner::new().scan_for_runs(
&mut self.layout_context.font_context(), &mut self.layout_context.font_context(),
unscanned_marker_fragments); unscanned_marker_fragments);
@ -1848,7 +1848,7 @@ fn control_chars_to_fragment(node: &InlineFragmentNodeInfo,
restyle_damage: RestyleDamage) restyle_damage: RestyleDamage)
-> Fragment { -> Fragment {
let info = SpecificFragmentInfo::UnscannedText( let info = SpecificFragmentInfo::UnscannedText(
UnscannedTextFragmentInfo::new(String::from(text), None)); box UnscannedTextFragmentInfo::new(String::from(text), None));
let mut style = node.style.clone(); let mut style = node.style.clone();
properties::modify_style_for_text(&mut style); properties::modify_style_for_text(&mut style);
Fragment::from_opaque_node_and_style(node.address, Fragment::from_opaque_node_and_style(node.address,

View file

@ -167,7 +167,7 @@ pub enum SpecificFragmentInfo {
TableWrapper, TableWrapper,
Multicol, Multicol,
MulticolColumn, MulticolColumn,
UnscannedText(UnscannedTextFragmentInfo), UnscannedText(Box<UnscannedTextFragmentInfo>),
} }
impl SpecificFragmentInfo { impl SpecificFragmentInfo {
@ -896,8 +896,8 @@ impl Fragment {
let mut unscanned_ellipsis_fragments = LinkedList::new(); let mut unscanned_ellipsis_fragments = LinkedList::new();
unscanned_ellipsis_fragments.push_back(self.transform( unscanned_ellipsis_fragments.push_back(self.transform(
self.border_box.size, self.border_box.size,
SpecificFragmentInfo::UnscannedText(UnscannedTextFragmentInfo::new("".to_owned(), SpecificFragmentInfo::UnscannedText(
None)))); box UnscannedTextFragmentInfo::new("".to_owned(), None))));
let ellipsis_fragments = TextRunScanner::new().scan_for_runs(&mut layout_context.font_context(), let ellipsis_fragments = TextRunScanner::new().scan_for_runs(&mut layout_context.font_context(),
unscanned_ellipsis_fragments); unscanned_ellipsis_fragments);
debug_assert!(ellipsis_fragments.len() == 1); debug_assert!(ellipsis_fragments.len() == 1);

View file

@ -434,7 +434,8 @@ fn render_text(layout_context: &LayoutContext,
string: String) string: String)
-> Option<SpecificFragmentInfo> { -> Option<SpecificFragmentInfo> {
let mut fragments = LinkedList::new(); let mut fragments = LinkedList::new();
let info = SpecificFragmentInfo::UnscannedText(UnscannedTextFragmentInfo::new(string, None)); let info = SpecificFragmentInfo::UnscannedText(
box UnscannedTextFragmentInfo::new(string, None));
fragments.push_back(Fragment::from_opaque_node_and_style(node, fragments.push_back(Fragment::from_opaque_node_and_style(node,
pseudo, pseudo,
style, style,

View file

@ -476,7 +476,7 @@ fn split_first_fragment_at_newline_if_necessary(fragments: &mut LinkedList<Fragm
} }
first_fragment.transform(first_fragment.border_box.size, first_fragment.transform(first_fragment.border_box.size,
SpecificFragmentInfo::UnscannedText( SpecificFragmentInfo::UnscannedText(
UnscannedTextFragmentInfo::new(string_before, box UnscannedTextFragmentInfo::new(string_before,
selection_before))) selection_before)))
}; };

View file

@ -7,7 +7,7 @@ use std::mem::size_of;
#[test] #[test]
fn test_size_of_fragment() { fn test_size_of_fragment() {
let expected = 184; let expected = 160;
let actual = size_of::<Fragment>(); let actual = size_of::<Fragment>();
if actual < expected { if actual < expected {