layout: Remove FontStyle in favor of using the font style struct

directly, and optimize `get_layout_font_group()` to use a small vector.

Seems to be a 38% layout win on a site I tested with a lot of text.
This commit is contained in:
Patrick Walton 2014-10-15 22:09:15 -07:00
parent f3066c70da
commit a6fcec468f
6 changed files with 52 additions and 87 deletions

View file

@ -32,7 +32,6 @@ use gfx::display_list::{LineDisplayItemClass, OpaqueNode, PseudoDisplayItemClass
use gfx::display_list::{SidewaysLeft, SidewaysRight, SolidColorDisplayItem};
use gfx::display_list::{SolidColorDisplayItemClass, StackingLevel, TextDisplayItem};
use gfx::display_list::{TextDisplayItemClass, Upright};
use gfx::font::FontStyle;
use gfx::text::glyph::CharIndex;
use gfx::text::text_run::TextRun;
use script_traits::UntrustedNodeAddress;
@ -707,8 +706,8 @@ impl Fragment {
}
pub fn calculate_line_height(&self, layout_context: &LayoutContext) -> Au {
let font_style = text::computed_style_to_font_style(&*self.style);
let font_metrics = text::font_metrics_for_style(layout_context.font_context(), &font_style);
let font_style = self.style.get_font();
let font_metrics = text::font_metrics_for_style(layout_context.font_context(), font_style);
text::line_height_from_style(&*self.style, &font_metrics)
}
@ -862,11 +861,6 @@ impl Fragment {
}
}
/// Converts this fragment's computed style to a font style used for rendering.
pub fn font_style(&self) -> FontStyle {
text::computed_style_to_font_style(self.style())
}
#[inline(always)]
pub fn style<'a>(&'a self) -> &'a ComputedValues {
&*self.style
@ -1834,9 +1828,9 @@ impl Fragment {
InlineBlockFragment(ref info) => {
// See CSS 2.1 § 10.8.1.
let block_flow = info.flow_ref.deref().as_immutable_block();
let font_style = text::computed_style_to_font_style(&*self.style);
let font_style = self.style.get_font();
let font_metrics = text::font_metrics_for_style(layout_context.font_context(),
&font_style);
font_style);
InlineMetrics::from_block_height(&font_metrics,
block_flow.base.position.size.block +
block_flow.fragment.margin.block_start_end())
@ -1872,7 +1866,7 @@ impl Fragment {
match (&self.specific, &other.specific) {
(&UnscannedTextFragment(_), &UnscannedTextFragment(_)) => {
// FIXME: Should probably use a whitelist of styles that can safely differ (#3165)
self.font_style() == other.font_style() &&
self.style().get_font() == other.style().get_font() &&
self.text_decoration() == other.text_decoration() &&
self.white_space() == other.white_space()
}