tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

custom_properties.rs (1502B)


      1 /* This Source Code Form is subject to the terms of the Mozilla Public
      2 * License, v. 2.0. If a copy of the MPL was not distributed with this
      3 * file, You can obtain one at https://mozilla.org/MPL/2.0/. */
      4 
      5 use cssparser::{Parser, ParserInput};
      6 use servo_arc::Arc;
      7 use style::custom_properties::{
      8    CssEnvironment, CustomPropertiesBuilder, CustomPropertiesMap, Name, SpecifiedValue,
      9 };
     10 use style::properties::CustomDeclarationValue;
     11 use test::{self, Bencher};
     12 
     13 fn cascade(
     14    name_and_value: &[(&str, &str)],
     15    inherited: Option<&Arc<CustomPropertiesMap>>,
     16 ) -> Option<Arc<CustomPropertiesMap>> {
     17    let values = name_and_value
     18        .iter()
     19        .map(|&(name, value)| {
     20            let mut input = ParserInput::new(value);
     21            let mut parser = Parser::new(&mut input);
     22            (
     23                Name::from(name),
     24                SpecifiedValue::parse(&mut parser).unwrap(),
     25            )
     26        })
     27        .collect::<Vec<_>>();
     28 
     29    let env = CssEnvironment;
     30    let mut builder = CustomPropertiesBuilder::new(inherited, &env);
     31 
     32    for &(ref name, ref val) in &values {
     33        builder.cascade(name, &CustomDeclarationValue::Value(val.clone()));
     34    }
     35 
     36    builder.build()
     37 }
     38 
     39 #[bench]
     40 fn cascade_custom_simple(b: &mut Bencher) {
     41    b.iter(|| {
     42        let parent = cascade(&[("foo", "10px"), ("bar", "100px")], None);
     43 
     44        test::black_box(cascade(
     45            &[("baz", "calc(40em + 4px)"), ("bazz", "calc(30em + 4px)")],
     46            parent.as_ref(),
     47        ))
     48    })
     49 }