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

@ -8,7 +8,9 @@ use std::string;
use std::rc::Rc;
use std::cell::RefCell;
use servo_util::cache::{Cache, HashCache};
use style::computed_values::{font_weight, font_style, font_variant};
use servo_util::smallvec::{SmallVec, SmallVec1};
use style::computed_values::{font_variant, font_weight};
use style::style_structs::Font as FontStyle;
use sync::Arc;
use servo_util::geometry::Au;
@ -82,22 +84,6 @@ pub struct FontMetrics {
pub line_gap: Au,
}
// TODO(Issue #179): eventually this will be split into the specified
// and used font styles. specified contains uninterpreted CSS font
// property values, while 'used' is attached to gfx::Font to descript
// the instance's properties.
//
// For now, the cases are differentiated with a typedef
#[deriving(Clone, PartialEq)]
pub struct FontStyle {
pub pt_size: f64,
pub weight: font_weight::T,
pub style: font_style::T,
pub families: Vec<String>,
pub variant: font_variant::T,
// TODO(Issue #198): font-stretch, text-decoration, size-adjust
}
pub type SpecifiedFontStyle = FontStyle;
pub type UsedFontStyle = FontStyle;
@ -174,13 +160,13 @@ impl Font {
}
pub struct FontGroup {
pub fonts: Vec<Rc<RefCell<Font>>>,
pub fonts: SmallVec1<Rc<RefCell<Font>>>,
}
impl FontGroup {
pub fn new(fonts: Vec<Rc<RefCell<Font>>>) -> FontGroup {
pub fn new(fonts: SmallVec1<Rc<RefCell<Font>>>) -> FontGroup {
FontGroup {
fonts: fonts
fonts: fonts,
}
}
@ -188,7 +174,7 @@ impl FontGroup {
assert!(self.fonts.len() > 0);
// TODO(Issue #177): Actually fall back through the FontGroup when a font is unsuitable.
TextRun::new(&mut *self.fonts[0].borrow_mut(), text.clone())
TextRun::new(&mut *self.fonts.get(0).borrow_mut(), text.clone())
}
}