mirror of
https://github.com/servo/servo.git
synced 2025-08-06 14:10:11 +01:00
gfx: Perform more aggressive caching in
`FontContext::get_layout_font_group_for_style()`. There are several optimizations here: * We make font families atoms, to allow for quicker comparisons. * We precalculate an FNV hash of the relevant fields of the font style structure. * When obtaining a platform font group, we first check pointer equality for the font style. If there's no match, we go to the FNV hash. Only if both caches miss do we construct and cache a font group. Note that individual fonts are *also* cached; thus there are two layers of caching here. 15% improvement in total layout thread time for Facebook Timeline.
This commit is contained in:
parent
6824bc9324
commit
750bbed2cb
14 changed files with 144 additions and 62 deletions
|
@ -2,18 +2,18 @@
|
|||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||
|
||||
use cssparser::{Token, Parser, DeclarationListParser, AtRuleParser, DeclarationParser};
|
||||
use std::ascii::AsciiExt;
|
||||
use stylesheets::CSSRule;
|
||||
use properties::longhands::font_family::parse_one_family;
|
||||
use computed_values::font_family::FontFamily;
|
||||
use cssparser::{Token, Parser, DeclarationListParser, AtRuleParser, DeclarationParser};
|
||||
use media_queries::Device;
|
||||
use url::{Url, UrlParser};
|
||||
use parser::{ParserContext, log_css_error};
|
||||
use properties::longhands::font_family::parse_one_family;
|
||||
use std::ascii::AsciiExt;
|
||||
use string_cache::Atom;
|
||||
use stylesheets::CSSRule;
|
||||
use url::{Url, UrlParser};
|
||||
|
||||
|
||||
pub fn iter_font_face_rules_inner<F>(rules: &[CSSRule], device: &Device,
|
||||
callback: &F) where F: Fn(&str, &Source) {
|
||||
pub fn iter_font_face_rules_inner<F>(rules: &[CSSRule], device: &Device, callback: &F)
|
||||
where F: Fn(&Atom, &Source) {
|
||||
for rule in rules.iter() {
|
||||
match *rule {
|
||||
CSSRule::Style(..) |
|
||||
|
@ -34,7 +34,7 @@ pub fn iter_font_face_rules_inner<F>(rules: &[CSSRule], device: &Device,
|
|||
#[derive(Clone, Debug, PartialEq, Eq)]
|
||||
pub enum Source {
|
||||
Url(UrlSource),
|
||||
Local(String),
|
||||
Local(Atom),
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, PartialEq, Eq)]
|
||||
|
@ -45,11 +45,10 @@ pub struct UrlSource {
|
|||
|
||||
#[derive(Debug, PartialEq, Eq)]
|
||||
pub struct FontFaceRule {
|
||||
pub family: String,
|
||||
pub family: Atom,
|
||||
pub sources: Vec<Source>,
|
||||
}
|
||||
|
||||
|
||||
pub fn parse_font_face_block(context: &ParserContext, input: &mut Parser)
|
||||
-> Result<FontFaceRule, ()> {
|
||||
let mut family = None;
|
||||
|
@ -83,7 +82,7 @@ pub fn parse_font_face_block(context: &ParserContext, input: &mut Parser)
|
|||
}
|
||||
|
||||
enum FontFaceDescriptorDeclaration {
|
||||
Family(String),
|
||||
Family(Atom),
|
||||
Src(Vec<Source>),
|
||||
}
|
||||
|
||||
|
@ -106,7 +105,8 @@ impl<'a, 'b> DeclarationParser for FontFaceRuleParser<'a, 'b> {
|
|||
fn parse_value(&self, name: &str, input: &mut Parser) -> Result<FontFaceDescriptorDeclaration, ()> {
|
||||
match_ignore_ascii_case! { name,
|
||||
"font-family" => {
|
||||
Ok(FontFaceDescriptorDeclaration::Family(try!(parse_one_non_generic_family_name(input))))
|
||||
Ok(FontFaceDescriptorDeclaration::Family(try!(
|
||||
parse_one_non_generic_family_name(input))))
|
||||
},
|
||||
"src" => {
|
||||
Ok(FontFaceDescriptorDeclaration::Src(try!(input.parse_comma_separated(|input| {
|
||||
|
@ -118,9 +118,9 @@ impl<'a, 'b> DeclarationParser for FontFaceRuleParser<'a, 'b> {
|
|||
}
|
||||
}
|
||||
|
||||
fn parse_one_non_generic_family_name(input: &mut Parser) -> Result<String, ()> {
|
||||
fn parse_one_non_generic_family_name(input: &mut Parser) -> Result<Atom, ()> {
|
||||
match parse_one_family(input) {
|
||||
Ok(FontFamily::FamilyName(name)) => Ok(name),
|
||||
Ok(FontFamily::FamilyName(name)) => Ok(name.clone()),
|
||||
_ => Err(())
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue