/* This Source Code Form is subject to the terms of the Mozilla Public *License,v.2.0.IfacopyoftheMPLwasnotdistributedwiththis
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */
use cssparser::SourceLocation; use rayon; use servo_arc::Arc; use servo_url::ServoUrl; use style::context::QuirksMode; use style::error_reporting::{ContextualParseError, ParseErrorReporter}; use style::media_queries::MediaList; use style::properties::{longhands, Importance, PropertyDeclaration, PropertyDeclarationBlock}; use style::rule_tree::{CascadeLevel, CascadeOrigin, RuleTree, StrongRuleNode, StyleSource}; use style::shared_lock::SharedRwLock; use style::stylesheets::{CssRule, Origin, Stylesheet}; use style::thread_state::{self, ThreadState}; use test::{self, Bencher};
impl<'a> Drop for AutoGCRuleTree<'a> { fn drop(&mutself) { unsafe { self.0.gc();
assert!(
::std::thread::panicking() || !self.0.root().has_children_for_testing(), "No rule nodes other than the root shall remain!"
);
}
}
}
fn parse_rules(css: &str) -> Vec<(StyleSource, CascadeLevel)> { let lock = SharedRwLock::new(); let media = Arc::new(lock.wrap(MediaList::empty()));
let s = Stylesheet::from_str(
css,
ServoUrl::parse("http://localhost").unwrap(),
Origin::Author,
media,
lock,
None,
Some(&ErrorringErrorReporter),
QuirksMode::NoQuirks, 0,
); let guard = s.shared_lock.read(); let rules = s.contents.rules.read_with(&guard);
rules
.0
.iter()
.filter_map(|rule| match *rule {
CssRule::Style(ref style_rule) => Some((
StyleSource::from_rule(style_rule.clone()),
CascadeLevel::new(CascadeOrigin::User),
)),
_ => None,
})
.collect()
}
#[bench] fn bench_expensive_insertion(b: &mut Bencher) { let r = RuleTree::new();
thread_state::initialize(ThreadState::SCRIPT);
// This test case tests a case where you style a bunch of siblings // matching the same rules, with a different style attribute each // one. let rules_matched = parse_rules( ".foo { width: 200px; } \
.bar { height: 500px; } \
.baz { display: block; }",
);
let shared_lock = SharedRwLock::new();
b.iter(|| { let _gc = AutoGCRuleTree::new(&r);
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.