From c0ee13bc8bf41a4cc60b871096a88438e9fc9c9d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Emilio=20Cobos=20=C3=81lvarez?= Date: Sun, 8 Oct 2017 06:04:28 -0500 Subject: [PATCH] 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 --- servo/components/style/custom_properties.rs | 11 +++-- .../style/properties/properties.mako.rs | 2 +- servo/components/style/thread_state.rs | 4 +- .../style/values/specified/image.rs | 12 ++--- servo/tests/unit/style/custom_properties.rs | 49 +++++++++++++++++++ servo/tests/unit/style/lib.rs | 1 + 6 files changed, 66 insertions(+), 13 deletions(-) create mode 100644 servo/tests/unit/style/custom_properties.rs diff --git a/servo/components/style/custom_properties.rs b/servo/components/style/custom_properties.rs index 9da84c3cc16f..7fd74f83c1be 100644 --- a/servo/components/style/custom_properties.rs +++ b/servo/components/style/custom_properties.rs @@ -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, 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 })) } diff --git a/servo/components/style/properties/properties.mako.rs b/servo/components/style/properties/properties.mako.rs index 7de94c689d98..031bd1e580b6 100644 --- a/servo/components/style/properties/properties.mako.rs +++ b/servo/components/style/properties/properties.mako.rs @@ -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))), diff --git a/servo/components/style/thread_state.rs b/servo/components/style/thread_state.rs index 894cdb4a813b..d06f47aabe4d 100644 --- a/servo/components/style/thread_state.rs +++ b/servo/components/style/thread_state.rs @@ -53,7 +53,9 @@ thread_local!(static STATE: RefCell> = 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); }); diff --git a/servo/components/style/values/specified/image.rs b/servo/components/style/values/specified/image.rs index 406f4beee3b7..feb4e044c932 100644 --- a/servo/components/style/values/specified/image.rs +++ b/servo/components/style/values/specified/image.rs @@ -908,18 +908,18 @@ impl Parse for ColorStop { } impl Parse for PaintWorklet { - fn parse<'i, 't>(context: &ParserContext, input: &mut Parser<'i, 't>) -> Result> { + fn parse<'i, 't>( + _context: &ParserContext, + input: &mut Parser<'i, 't>, + ) -> Result> { 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 }) }) } } diff --git a/servo/tests/unit/style/custom_properties.rs b/servo/tests/unit/style/custom_properties.rs new file mode 100644 index 000000000000..135583e9d62a --- /dev/null +++ b/servo/tests/unit/style/custom_properties.rs @@ -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>, +) -> Option> { + 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::>(); + + 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())) + }) +} diff --git a/servo/tests/unit/style/lib.rs b/servo/tests/unit/style/lib.rs index f1774fe1a094..c1eab17d1b60 100644 --- a/servo/tests/unit/style/lib.rs +++ b/servo/tests/unit/style/lib.rs @@ -24,6 +24,7 @@ extern crate test; mod animated_properties; mod attr; +mod custom_properties; mod keyframes; mod logical_geometry; mod media_queries;