mirror of
https://github.com/servo/servo.git
synced 2025-06-18 05:14:28 +00:00
`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.
47 lines
1.5 KiB
Rust
47 lines
1.5 KiB
Rust
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
* 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 selectors::parser::ParserContext as SelectorParserContext;
|
|
use cssparser::{Parser, SourcePosition};
|
|
use url::{Url, UrlParser};
|
|
use log;
|
|
|
|
use stylesheets::Origin;
|
|
|
|
pub struct ParserContext<'a> {
|
|
pub base_url: &'a Url,
|
|
pub selector_context: SelectorParserContext,
|
|
}
|
|
|
|
impl<'a> ParserContext<'a> {
|
|
pub fn new(stylesheet_origin: Origin, base_url: &'a Url) -> ParserContext<'a> {
|
|
let mut selector_context = SelectorParserContext::new();
|
|
selector_context.in_user_agent_stylesheet = stylesheet_origin == Origin::UserAgent;
|
|
ParserContext {
|
|
base_url: base_url,
|
|
selector_context: selector_context,
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
impl<'a> ParserContext<'a> {
|
|
pub fn parse_url(&self, input: &str) -> Url {
|
|
UrlParser::new().base_url(self.base_url).parse(input)
|
|
.unwrap_or_else(|_| Url::parse("about:invalid").unwrap())
|
|
}
|
|
}
|
|
|
|
|
|
/// Defaults to a no-op.
|
|
/// Set a `RUST_LOG=style::errors` environment variable
|
|
/// to log CSS parse errors to stderr.
|
|
pub fn log_css_error(input: &mut Parser, position: SourcePosition, message: &str) {
|
|
if log_enabled!(log::INFO) {
|
|
let location = input.source_location(position);
|
|
// TODO eventually this will got into a "web console" or something.
|
|
info!("{}:{} {}", location.line, location.column, message)
|
|
}
|
|
}
|