mirror of
https://github.com/servo/servo.git
synced 2025-08-04 21:20:23 +01:00
auto merge of #2581 : mbrubeck/servo/declarations-cache, r=pcwalton
Fixes #2498. Also includes a reftest, and some related code cleanup (in separate commits). Note: The fix in `properties.rs.mako` is much more readable with `git diff -w`.
This commit is contained in:
commit
41a6234b39
6 changed files with 63 additions and 31 deletions
|
@ -131,7 +131,7 @@ impl<'a> Hash for ApplicableDeclarationsCacheQuery<'a> {
|
||||||
static APPLICABLE_DECLARATIONS_CACHE_SIZE: uint = 32;
|
static APPLICABLE_DECLARATIONS_CACHE_SIZE: uint = 32;
|
||||||
|
|
||||||
pub struct ApplicableDeclarationsCache {
|
pub struct ApplicableDeclarationsCache {
|
||||||
pub cache: SimpleHashCache<ApplicableDeclarationsCacheEntry,Arc<ComputedValues>>,
|
cache: SimpleHashCache<ApplicableDeclarationsCacheEntry,Arc<ComputedValues>>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl ApplicableDeclarationsCache {
|
impl ApplicableDeclarationsCache {
|
||||||
|
@ -149,7 +149,7 @@ impl ApplicableDeclarationsCache {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn insert(&mut self, declarations: &[MatchedProperty], style: Arc<ComputedValues>) {
|
fn insert(&mut self, declarations: &[MatchedProperty], style: Arc<ComputedValues>) {
|
||||||
drop(self.cache.insert(ApplicableDeclarationsCacheEntry::new(declarations), style))
|
self.cache.insert(ApplicableDeclarationsCacheEntry::new(declarations), style)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -340,12 +340,11 @@ impl<'ln> PrivateMatchMethods for LayoutNode<'ln> {
|
||||||
let cacheable;
|
let cacheable;
|
||||||
match parent_style {
|
match parent_style {
|
||||||
Some(ref parent_style) => {
|
Some(ref parent_style) => {
|
||||||
let cached_computed_values;
|
|
||||||
let cache_entry = applicable_declarations_cache.find(applicable_declarations);
|
let cache_entry = applicable_declarations_cache.find(applicable_declarations);
|
||||||
match cache_entry {
|
let cached_computed_values = match cache_entry {
|
||||||
None => cached_computed_values = None,
|
None => None,
|
||||||
Some(ref style) => cached_computed_values = Some(&**style),
|
Some(ref style) => Some(&**style),
|
||||||
}
|
};
|
||||||
let (the_style, is_cacheable) = cascade(applicable_declarations,
|
let (the_style, is_cacheable) = cascade(applicable_declarations,
|
||||||
shareable,
|
shareable,
|
||||||
Some(&***parent_style),
|
Some(&***parent_style),
|
||||||
|
|
|
@ -1653,10 +1653,10 @@ fn cascade_with_cached_declarations(applicable_declarations: &[MatchedProperty],
|
||||||
for declaration in sub_list.declarations.iter() {
|
for declaration in sub_list.declarations.iter() {
|
||||||
match *declaration {
|
match *declaration {
|
||||||
% for style_struct in STYLE_STRUCTS:
|
% for style_struct in STYLE_STRUCTS:
|
||||||
% if style_struct.inherited:
|
|
||||||
% for property in style_struct.longhands:
|
% for property in style_struct.longhands:
|
||||||
% if property.derived_from is None:
|
% if property.derived_from is None:
|
||||||
${property.camel_case}Declaration(ref declared_value) => {
|
${property.camel_case}Declaration(ref declared_value) => {
|
||||||
|
% if style_struct.inherited:
|
||||||
if seen.get_${property.ident}() {
|
if seen.get_${property.ident}() {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
@ -1681,8 +1681,14 @@ fn cascade_with_cached_declarations(applicable_declarations: &[MatchedProperty],
|
||||||
};
|
};
|
||||||
style_${style_struct.ident}.make_unique_experimental()
|
style_${style_struct.ident}.make_unique_experimental()
|
||||||
.${property.ident} = computed_value;
|
.${property.ident} = computed_value;
|
||||||
|
% endif
|
||||||
|
|
||||||
% if property.name in DERIVED_LONGHANDS:
|
% if property.name in DERIVED_LONGHANDS:
|
||||||
|
% if not style_struct.inherited:
|
||||||
|
// Use the cached value.
|
||||||
|
let computed_value = style_${style_struct.ident}
|
||||||
|
.${property.ident}.clone();
|
||||||
|
% endif
|
||||||
% for derived in DERIVED_LONGHANDS[property.name]:
|
% for derived in DERIVED_LONGHANDS[property.name]:
|
||||||
style_${derived.style_struct.ident}
|
style_${derived.style_struct.ident}
|
||||||
.make_unique_experimental()
|
.make_unique_experimental()
|
||||||
|
@ -1700,9 +1706,7 @@ fn cascade_with_cached_declarations(applicable_declarations: &[MatchedProperty],
|
||||||
}
|
}
|
||||||
% endif
|
% endif
|
||||||
% endfor
|
% endfor
|
||||||
% endif
|
|
||||||
% endfor
|
% endfor
|
||||||
_ => {}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -216,7 +216,7 @@ impl<K:Clone+Eq+Hash,V:Clone> SimpleHashCache<K,V> {
|
||||||
impl<K:Clone+Eq+Hash,V:Clone> Cache<K,V> for SimpleHashCache<K,V> {
|
impl<K:Clone+Eq+Hash,V:Clone> Cache<K,V> for SimpleHashCache<K,V> {
|
||||||
fn insert(&mut self, key: K, value: V) {
|
fn insert(&mut self, key: K, value: V) {
|
||||||
let bucket_index = self.bucket_for_key(&key);
|
let bucket_index = self.bucket_for_key(&key);
|
||||||
*self.entries.get_mut(bucket_index) = Some((key, value))
|
*self.entries.get_mut(bucket_index) = Some((key, value));
|
||||||
}
|
}
|
||||||
|
|
||||||
fn find(&mut self, key: &K) -> Option<V> {
|
fn find(&mut self, key: &K) -> Option<V> {
|
||||||
|
|
|
@ -18,6 +18,7 @@
|
||||||
== border_style_none_a.html border_style_none_b.html
|
== border_style_none_a.html border_style_none_b.html
|
||||||
== borders_a.html borders_b.html
|
== borders_a.html borders_b.html
|
||||||
== acid1_a.html acid1_b.html
|
== acid1_a.html acid1_b.html
|
||||||
|
== text_decoration_cached.html text_decoration_cached_ref.html
|
||||||
# text_decoration_propagation_a.html text_decoration_propagation_b.html
|
# text_decoration_propagation_a.html text_decoration_propagation_b.html
|
||||||
# inline_text_align_a.html inline_text_align_b.html
|
# inline_text_align_a.html inline_text_align_b.html
|
||||||
== font_size_em.html font_size_em_ref.html
|
== font_size_em.html font_size_em_ref.html
|
||||||
|
|
14
src/test/ref/text_decoration_cached.html
Normal file
14
src/test/ref/text_decoration_cached.html
Normal file
|
@ -0,0 +1,14 @@
|
||||||
|
<!DOCTYPE html>
|
||||||
|
<html>
|
||||||
|
<head>
|
||||||
|
<meta charset="UTF-8">
|
||||||
|
<title>text-decoration cache test</title>
|
||||||
|
<style>
|
||||||
|
span { text-decoration: underline; }
|
||||||
|
</style>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<u>test</u>
|
||||||
|
<u>test</u>
|
||||||
|
<body>
|
||||||
|
</html>
|
14
src/test/ref/text_decoration_cached_ref.html
Normal file
14
src/test/ref/text_decoration_cached_ref.html
Normal file
|
@ -0,0 +1,14 @@
|
||||||
|
<!DOCTYPE html>
|
||||||
|
<html>
|
||||||
|
<head>
|
||||||
|
<meta charset="UTF-8">
|
||||||
|
<title>text-decoration cache reference</title>
|
||||||
|
<style>
|
||||||
|
span { text-decoration: underline; }
|
||||||
|
</style>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<u>test</u>
|
||||||
|
<span>test</span>
|
||||||
|
<body>
|
||||||
|
</html>
|
Loading…
Add table
Add a link
Reference in a new issue