mirror of
https://github.com/mozilla/gecko-dev.git
synced 2025-02-05 22:05:40 +00:00
servo: Merge #18781 - style: Add a simple custom properties benchmark (from emilio:custom-props-bench); r=heycam
This is going to help the work in bug 1405411. Source-Repo: https://github.com/servo/servo Source-Revision: 47efcd5e52afd62dcd84ba350948039f67613e20 --HG-- extra : subtree_source : https%3A//hg.mozilla.org/projects/converted-servo-linear extra : subtree_revision : 3194de3a0a9c123f0a507e4d2f6e01abd89b3d69
This commit is contained in:
parent
005f263340
commit
c0ee13bc8b
@ -8,7 +8,6 @@
|
||||
|
||||
use Atom;
|
||||
use cssparser::{Delimiter, Parser, ParserInput, SourcePosition, Token, TokenSerializationType};
|
||||
use parser::ParserContext;
|
||||
use precomputed_hash::PrecomputedHash;
|
||||
use properties::{CSSWideKeyword, DeclaredValue};
|
||||
use selector_map::{PrecomputedHashSet, PrecomputedDiagnosticHashMap};
|
||||
@ -246,15 +245,17 @@ impl ComputedValue {
|
||||
impl SpecifiedValue {
|
||||
/// Parse a custom property SpecifiedValue.
|
||||
pub fn parse<'i, 't>(
|
||||
_context: &ParserContext,
|
||||
input: &mut Parser<'i, 't>,
|
||||
) -> Result<Box<Self>, ParseError<'i>> {
|
||||
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 {
|
||||
css: css.into_owned(),
|
||||
first_token_type: first,
|
||||
last_token_type: last,
|
||||
first_token_type,
|
||||
last_token_type,
|
||||
references
|
||||
}))
|
||||
}
|
||||
|
@ -1635,7 +1635,7 @@ impl PropertyDeclaration {
|
||||
// This probably affects some test results.
|
||||
let value = match input.try(|i| CSSWideKeyword::parse(i)) {
|
||||
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),
|
||||
Err(e) => return Err(PropertyDeclarationParseError::InvalidValue(name.to_string().into(),
|
||||
ValueParseError::from_parse_error(e))),
|
||||
|
@ -53,7 +53,9 @@ thread_local!(static STATE: RefCell<Option<ThreadState>> = RefCell::new(None));
|
||||
pub fn initialize(x: ThreadState) {
|
||||
STATE.with(|ref k| {
|
||||
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);
|
||||
});
|
||||
|
@ -908,18 +908,18 @@ impl Parse for ColorStop {
|
||||
}
|
||||
|
||||
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.parse_nested_block(|input| {
|
||||
let name = Atom::from(&**input.expect_ident()?);
|
||||
let arguments = input.try(|input| {
|
||||
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![]);
|
||||
Ok(PaintWorklet {
|
||||
name: name,
|
||||
arguments: arguments,
|
||||
})
|
||||
Ok(PaintWorklet { name, arguments })
|
||||
})
|
||||
}
|
||||
}
|
||||
|
49
servo/tests/unit/style/custom_properties.rs
Normal file
49
servo/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 attr;
|
||||
mod custom_properties;
|
||||
mod keyframes;
|
||||
mod logical_geometry;
|
||||
mod media_queries;
|
||||
|
Loading…
x
Reference in New Issue
Block a user