mirror of
https://github.com/servo/servo.git
synced 2025-08-07 14:35:33 +01:00
Auto merge of #18781 - emilio:custom-props-bench, r=heycam
style: Add a simple custom properties benchmark. This is going to help the work in bug 1405411. <!-- Reviewable:start --> --- This change is [<img src="https://reviewable.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/servo/18781) <!-- Reviewable:end -->
This commit is contained in:
commit
47efcd5e52
6 changed files with 66 additions and 13 deletions
|
@ -8,7 +8,6 @@
|
||||||
|
|
||||||
use Atom;
|
use Atom;
|
||||||
use cssparser::{Delimiter, Parser, ParserInput, SourcePosition, Token, TokenSerializationType};
|
use cssparser::{Delimiter, Parser, ParserInput, SourcePosition, Token, TokenSerializationType};
|
||||||
use parser::ParserContext;
|
|
||||||
use precomputed_hash::PrecomputedHash;
|
use precomputed_hash::PrecomputedHash;
|
||||||
use properties::{CSSWideKeyword, DeclaredValue};
|
use properties::{CSSWideKeyword, DeclaredValue};
|
||||||
use selector_map::{PrecomputedHashSet, PrecomputedDiagnosticHashMap};
|
use selector_map::{PrecomputedHashSet, PrecomputedDiagnosticHashMap};
|
||||||
|
@ -246,15 +245,17 @@ impl ComputedValue {
|
||||||
impl SpecifiedValue {
|
impl SpecifiedValue {
|
||||||
/// Parse a custom property SpecifiedValue.
|
/// Parse a custom property SpecifiedValue.
|
||||||
pub fn parse<'i, 't>(
|
pub fn parse<'i, 't>(
|
||||||
_context: &ParserContext,
|
|
||||||
input: &mut Parser<'i, 't>,
|
input: &mut Parser<'i, 't>,
|
||||||
) -> Result<Box<Self>, ParseError<'i>> {
|
) -> Result<Box<Self>, ParseError<'i>> {
|
||||||
let mut references = PrecomputedHashSet::default();
|
let mut references = PrecomputedHashSet::default();
|
||||||
let (first, css, last) = parse_self_contained_declaration_value(input, Some(&mut references))?;
|
|
||||||
|
let (first_token_type, css, last_token_type) =
|
||||||
|
parse_self_contained_declaration_value(input, Some(&mut references))?;
|
||||||
|
|
||||||
Ok(Box::new(SpecifiedValue {
|
Ok(Box::new(SpecifiedValue {
|
||||||
css: css.into_owned(),
|
css: css.into_owned(),
|
||||||
first_token_type: first,
|
first_token_type,
|
||||||
last_token_type: last,
|
last_token_type,
|
||||||
references
|
references
|
||||||
}))
|
}))
|
||||||
}
|
}
|
||||||
|
|
|
@ -1635,7 +1635,7 @@ impl PropertyDeclaration {
|
||||||
// This probably affects some test results.
|
// This probably affects some test results.
|
||||||
let value = match input.try(|i| CSSWideKeyword::parse(i)) {
|
let value = match input.try(|i| CSSWideKeyword::parse(i)) {
|
||||||
Ok(keyword) => DeclaredValueOwned::CSSWideKeyword(keyword),
|
Ok(keyword) => DeclaredValueOwned::CSSWideKeyword(keyword),
|
||||||
Err(()) => match ::custom_properties::SpecifiedValue::parse(context, input) {
|
Err(()) => match ::custom_properties::SpecifiedValue::parse(input) {
|
||||||
Ok(value) => DeclaredValueOwned::Value(value),
|
Ok(value) => DeclaredValueOwned::Value(value),
|
||||||
Err(e) => return Err(PropertyDeclarationParseError::InvalidValue(name.to_string().into(),
|
Err(e) => return Err(PropertyDeclarationParseError::InvalidValue(name.to_string().into(),
|
||||||
ValueParseError::from_parse_error(e))),
|
ValueParseError::from_parse_error(e))),
|
||||||
|
|
|
@ -53,7 +53,9 @@ thread_local!(static STATE: RefCell<Option<ThreadState>> = RefCell::new(None));
|
||||||
pub fn initialize(x: ThreadState) {
|
pub fn initialize(x: ThreadState) {
|
||||||
STATE.with(|ref k| {
|
STATE.with(|ref k| {
|
||||||
if let Some(ref s) = *k.borrow() {
|
if let Some(ref s) = *k.borrow() {
|
||||||
panic!("Thread state already initialized as {:?}", s);
|
if x != *s {
|
||||||
|
panic!("Thread state already initialized as {:?}", s);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
*k.borrow_mut() = Some(x);
|
*k.borrow_mut() = Some(x);
|
||||||
});
|
});
|
||||||
|
|
|
@ -908,18 +908,18 @@ impl Parse for ColorStop {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Parse for PaintWorklet {
|
impl Parse for PaintWorklet {
|
||||||
fn parse<'i, 't>(context: &ParserContext, input: &mut Parser<'i, 't>) -> Result<Self, ParseError<'i>> {
|
fn parse<'i, 't>(
|
||||||
|
_context: &ParserContext,
|
||||||
|
input: &mut Parser<'i, 't>,
|
||||||
|
) -> Result<Self, ParseError<'i>> {
|
||||||
input.expect_function_matching("paint")?;
|
input.expect_function_matching("paint")?;
|
||||||
input.parse_nested_block(|input| {
|
input.parse_nested_block(|input| {
|
||||||
let name = Atom::from(&**input.expect_ident()?);
|
let name = Atom::from(&**input.expect_ident()?);
|
||||||
let arguments = input.try(|input| {
|
let arguments = input.try(|input| {
|
||||||
input.expect_comma()?;
|
input.expect_comma()?;
|
||||||
input.parse_comma_separated(|input| Ok(*SpecifiedValue::parse(context, input)?))
|
input.parse_comma_separated(|input| Ok(*SpecifiedValue::parse(input)?))
|
||||||
}).unwrap_or(vec![]);
|
}).unwrap_or(vec![]);
|
||||||
Ok(PaintWorklet {
|
Ok(PaintWorklet { name, arguments })
|
||||||
name: name,
|
|
||||||
arguments: arguments,
|
|
||||||
})
|
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
49
tests/unit/style/custom_properties.rs
Normal file
49
tests/unit/style/custom_properties.rs
Normal file
|
@ -0,0 +1,49 @@
|
||||||
|
/* 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 cssparser::{Parser, ParserInput};
|
||||||
|
use servo_arc::Arc;
|
||||||
|
use style::custom_properties::{self, Name, SpecifiedValue, CustomPropertiesMap};
|
||||||
|
use style::properties::DeclaredValue;
|
||||||
|
use test::{self, Bencher};
|
||||||
|
|
||||||
|
fn cascade(
|
||||||
|
name_and_value: &[(&str, &str)],
|
||||||
|
inherited: Option<&Arc<CustomPropertiesMap>>,
|
||||||
|
) -> Option<Arc<CustomPropertiesMap>> {
|
||||||
|
let values = name_and_value.iter().map(|&(name, value)| {
|
||||||
|
let mut input = ParserInput::new(value);
|
||||||
|
let mut parser = Parser::new(&mut input);
|
||||||
|
(Name::from(name), SpecifiedValue::parse(&mut parser).unwrap())
|
||||||
|
}).collect::<Vec<_>>();
|
||||||
|
|
||||||
|
let mut custom_properties = None;
|
||||||
|
let mut seen = Default::default();
|
||||||
|
for &(ref name, ref val) in &values {
|
||||||
|
custom_properties::cascade(
|
||||||
|
&mut custom_properties,
|
||||||
|
inherited,
|
||||||
|
&mut seen,
|
||||||
|
name,
|
||||||
|
DeclaredValue::Value(val)
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
custom_properties::finish_cascade(custom_properties, inherited)
|
||||||
|
}
|
||||||
|
|
||||||
|
#[bench]
|
||||||
|
fn cascade_custom_simple(b: &mut Bencher) {
|
||||||
|
b.iter(|| {
|
||||||
|
let parent = cascade(&[
|
||||||
|
("foo", "10px"),
|
||||||
|
("bar", "100px"),
|
||||||
|
], None);
|
||||||
|
|
||||||
|
test::black_box(cascade(&[
|
||||||
|
("baz", "calc(40em + 4px)"),
|
||||||
|
("bazz", "calc(30em + 4px)"),
|
||||||
|
], parent.as_ref()))
|
||||||
|
})
|
||||||
|
}
|
|
@ -24,6 +24,7 @@ extern crate test;
|
||||||
|
|
||||||
mod animated_properties;
|
mod animated_properties;
|
||||||
mod attr;
|
mod attr;
|
||||||
|
mod custom_properties;
|
||||||
mod keyframes;
|
mod keyframes;
|
||||||
mod logical_geometry;
|
mod logical_geometry;
|
||||||
mod media_queries;
|
mod media_queries;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue