mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-10-12 12:55:46 +00:00
servo: Merge #18803 - style: more custom properties optimizations (from heycam:more-custom-prop-opts); r=emilio
These help slightly with https://bugzilla.mozilla.org/show_bug.cgi?id=1405411. Source-Repo: https://github.com/servo/servo Source-Revision: 99e15f0f03fceb97f2dd54e049fc133a7001c157 --HG-- extra : subtree_source : https%3A//hg.mozilla.org/projects/converted-servo-linear extra : subtree_revision : dc9f5bbe50ec95ccb8dcc41842ce6c93e1afc50f
This commit is contained in:
parent
88c55f4a2c
commit
7c1afe6a7f
@ -507,11 +507,15 @@ impl<'a> CustomPropertiesBuilder<'a> {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if !self.value_may_affect_style(name, &specified_value) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if self.custom_properties.is_none() {
|
if self.custom_properties.is_none() {
|
||||||
self.custom_properties = Some(match self.inherited {
|
self.custom_properties = Some(match self.inherited {
|
||||||
Some(inherited) => (**inherited).clone(),
|
Some(inherited) => (**inherited).clone(),
|
||||||
None => CustomPropertiesMap::new(),
|
None => CustomPropertiesMap::new(),
|
||||||
})
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
let map = self.custom_properties.as_mut().unwrap();
|
let map = self.custom_properties.as_mut().unwrap();
|
||||||
@ -525,12 +529,52 @@ impl<'a> CustomPropertiesBuilder<'a> {
|
|||||||
CSSWideKeyword::Initial => {
|
CSSWideKeyword::Initial => {
|
||||||
map.remove(name);
|
map.remove(name);
|
||||||
}
|
}
|
||||||
CSSWideKeyword::Unset | // Custom properties are inherited by default.
|
// handled in value_may_affect_style
|
||||||
CSSWideKeyword::Inherit => {} // The inherited value is what we already have.
|
CSSWideKeyword::Unset |
|
||||||
|
CSSWideKeyword::Inherit => unreachable!(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn value_may_affect_style(
|
||||||
|
&self,
|
||||||
|
name: &Name,
|
||||||
|
value: &DeclaredValue<Arc<SpecifiedValue>>
|
||||||
|
) -> bool {
|
||||||
|
match *value {
|
||||||
|
DeclaredValue::CSSWideKeyword(CSSWideKeyword::Unset) |
|
||||||
|
DeclaredValue::CSSWideKeyword(CSSWideKeyword::Inherit) => {
|
||||||
|
// Custom properties are inherited by default. So
|
||||||
|
// explicit 'inherit' or 'unset' means we can just use
|
||||||
|
// any existing value in the inherited CustomPropertiesMap.
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
_ => {}
|
||||||
|
}
|
||||||
|
|
||||||
|
let existing_value =
|
||||||
|
self.custom_properties.as_ref().and_then(|m| m.get(name))
|
||||||
|
.or_else(|| self.inherited.and_then(|m| m.get(name)));
|
||||||
|
|
||||||
|
match (existing_value, value) {
|
||||||
|
(None, &DeclaredValue::CSSWideKeyword(CSSWideKeyword::Initial)) => {
|
||||||
|
// The initial value of a custom property is the same as it
|
||||||
|
// not existing in the map.
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
(Some(existing_value), &DeclaredValue::Value(specified_value)) => {
|
||||||
|
// Don't bother overwriting an existing inherited value with
|
||||||
|
// the same specified value.
|
||||||
|
if existing_value == specified_value {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
_ => {}
|
||||||
|
}
|
||||||
|
|
||||||
|
true
|
||||||
|
}
|
||||||
|
|
||||||
/// Returns the final map of applicable custom properties.
|
/// Returns the final map of applicable custom properties.
|
||||||
///
|
///
|
||||||
/// If there was any specified property, we've created a new map and now we need
|
/// If there was any specified property, we've created a new map and now we need
|
||||||
|
Loading…
Reference in New Issue
Block a user