mirror of
https://github.com/servo/servo.git
synced 2025-06-20 07:08:59 +01:00
Auto merge of #18414 - jdm:animdecl-codesize, r=SimonSapin
Reduce the size of AnimationValue code According to bloaty, these commits shave off 25k from code in the animated_properties module. --- - [X] `./mach build -d` does not report any errors - [X] `./mach test-tidy` does not report any errors <!-- Reviewable:start --> --- This change is [<img src="https://reviewable.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/servo/18414) <!-- Reviewable:end -->
This commit is contained in:
commit
eff768679d
2 changed files with 42 additions and 29 deletions
|
@ -407,7 +407,7 @@ impl AnimationValue {
|
||||||
) -> Option<Self> {
|
) -> Option<Self> {
|
||||||
use properties::LonghandId;
|
use properties::LonghandId;
|
||||||
|
|
||||||
match *decl {
|
let animatable = match *decl {
|
||||||
% for prop in data.longhands:
|
% for prop in data.longhands:
|
||||||
% if prop.animatable:
|
% if prop.animatable:
|
||||||
PropertyDeclaration::${prop.camel_case}(ref val) => {
|
PropertyDeclaration::${prop.camel_case}(ref val) => {
|
||||||
|
@ -427,13 +427,13 @@ impl AnimationValue {
|
||||||
% else:
|
% else:
|
||||||
let computed = val.to_computed_value(context);
|
let computed = val.to_computed_value(context);
|
||||||
% endif
|
% endif
|
||||||
Some(AnimationValue::${prop.camel_case}(
|
AnimationValue::${prop.camel_case}(
|
||||||
% if prop.is_animatable_with_computed_value:
|
% if prop.is_animatable_with_computed_value:
|
||||||
computed
|
computed
|
||||||
% else:
|
% else:
|
||||||
computed.to_animated_value()
|
computed.to_animated_value()
|
||||||
% endif
|
% endif
|
||||||
))
|
)
|
||||||
},
|
},
|
||||||
% endif
|
% endif
|
||||||
% endfor
|
% endfor
|
||||||
|
@ -444,33 +444,32 @@ impl AnimationValue {
|
||||||
% for prop in data.longhands:
|
% for prop in data.longhands:
|
||||||
% if prop.animatable:
|
% if prop.animatable:
|
||||||
LonghandId::${prop.camel_case} => {
|
LonghandId::${prop.camel_case} => {
|
||||||
let computed = match keyword {
|
let style_struct = match keyword {
|
||||||
% if not prop.style_struct.inherited:
|
% if not prop.style_struct.inherited:
|
||||||
CSSWideKeyword::Unset |
|
CSSWideKeyword::Unset |
|
||||||
% endif
|
% endif
|
||||||
CSSWideKeyword::Initial => {
|
CSSWideKeyword::Initial => {
|
||||||
let initial_struct = initial.get_${prop.style_struct.name_lower}();
|
initial.get_${prop.style_struct.name_lower}()
|
||||||
initial_struct.clone_${prop.ident}()
|
|
||||||
},
|
},
|
||||||
% if prop.style_struct.inherited:
|
% if prop.style_struct.inherited:
|
||||||
CSSWideKeyword::Unset |
|
CSSWideKeyword::Unset |
|
||||||
% endif
|
% endif
|
||||||
CSSWideKeyword::Inherit => {
|
CSSWideKeyword::Inherit => {
|
||||||
let inherit_struct = context.builder
|
context.builder
|
||||||
.get_parent_${prop.style_struct.name_lower}();
|
.get_parent_${prop.style_struct.name_lower}()
|
||||||
inherit_struct.clone_${prop.ident}()
|
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
let computed = style_struct.clone_${prop.ident}();
|
||||||
% if not prop.is_animatable_with_computed_value:
|
% if not prop.is_animatable_with_computed_value:
|
||||||
let computed = computed.to_animated_value();
|
let computed = computed.to_animated_value();
|
||||||
% endif
|
% endif
|
||||||
Some(AnimationValue::${prop.camel_case}(computed))
|
AnimationValue::${prop.camel_case}(computed)
|
||||||
},
|
},
|
||||||
% endif
|
% endif
|
||||||
% endfor
|
% endfor
|
||||||
% for prop in data.longhands:
|
% for prop in data.longhands:
|
||||||
% if not prop.animatable:
|
% if not prop.animatable:
|
||||||
LonghandId::${prop.camel_case} => None,
|
LonghandId::${prop.camel_case} => return None,
|
||||||
% endif
|
% endif
|
||||||
% endfor
|
% endfor
|
||||||
}
|
}
|
||||||
|
@ -486,15 +485,16 @@ impl AnimationValue {
|
||||||
context.quirks_mode
|
context.quirks_mode
|
||||||
)
|
)
|
||||||
};
|
};
|
||||||
AnimationValue::from_declaration(
|
return AnimationValue::from_declaration(
|
||||||
&substituted,
|
&substituted,
|
||||||
context,
|
context,
|
||||||
extra_custom_properties,
|
extra_custom_properties,
|
||||||
initial,
|
initial,
|
||||||
)
|
)
|
||||||
},
|
},
|
||||||
_ => None // non animatable properties will get included because of shorthands. ignore.
|
_ => return None // non animatable properties will get included because of shorthands. ignore.
|
||||||
}
|
};
|
||||||
|
Some(animatable)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Get an AnimationValue for an AnimatableLonghand from a given computed values.
|
/// Get an AnimationValue for an AnimatableLonghand from a given computed values.
|
||||||
|
@ -524,9 +524,17 @@ impl AnimationValue {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn animate_discrete<T: Clone>(this: &T, other: &T, procedure: Procedure) -> Result<T, ()> {
|
||||||
|
if let Procedure::Interpolate { progress } = procedure {
|
||||||
|
Ok(if progress < 0.5 { this.clone() } else { other.clone() })
|
||||||
|
} else {
|
||||||
|
Err(())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
impl Animate for AnimationValue {
|
impl Animate for AnimationValue {
|
||||||
fn animate(&self, other: &Self, procedure: Procedure) -> Result<Self, ()> {
|
fn animate(&self, other: &Self, procedure: Procedure) -> Result<Self, ()> {
|
||||||
match (self, other) {
|
let value = match (self, other) {
|
||||||
% for prop in data.longhands:
|
% for prop in data.longhands:
|
||||||
% if prop.animatable:
|
% if prop.animatable:
|
||||||
% if prop.animation_value_type != "discrete":
|
% if prop.animation_value_type != "discrete":
|
||||||
|
@ -534,22 +542,18 @@ impl Animate for AnimationValue {
|
||||||
&AnimationValue::${prop.camel_case}(ref this),
|
&AnimationValue::${prop.camel_case}(ref this),
|
||||||
&AnimationValue::${prop.camel_case}(ref other),
|
&AnimationValue::${prop.camel_case}(ref other),
|
||||||
) => {
|
) => {
|
||||||
Ok(AnimationValue::${prop.camel_case}(
|
AnimationValue::${prop.camel_case}(
|
||||||
this.animate(other, procedure)?,
|
this.animate(other, procedure)?,
|
||||||
))
|
)
|
||||||
},
|
},
|
||||||
% else:
|
% else:
|
||||||
(
|
(
|
||||||
&AnimationValue::${prop.camel_case}(ref this),
|
&AnimationValue::${prop.camel_case}(ref this),
|
||||||
&AnimationValue::${prop.camel_case}(ref other),
|
&AnimationValue::${prop.camel_case}(ref other),
|
||||||
) => {
|
) => {
|
||||||
if let Procedure::Interpolate { progress } = procedure {
|
AnimationValue::${prop.camel_case}(
|
||||||
Ok(AnimationValue::${prop.camel_case}(
|
animate_discrete(this, other, procedure)?
|
||||||
if progress < 0.5 { this.clone() } else { other.clone() },
|
)
|
||||||
))
|
|
||||||
} else {
|
|
||||||
Err(())
|
|
||||||
}
|
|
||||||
},
|
},
|
||||||
% endif
|
% endif
|
||||||
% endif
|
% endif
|
||||||
|
@ -557,12 +561,23 @@ impl Animate for AnimationValue {
|
||||||
_ => {
|
_ => {
|
||||||
panic!("Unexpected AnimationValue::animate call, got: {:?}, {:?}", self, other);
|
panic!("Unexpected AnimationValue::animate call, got: {:?}, {:?}", self, other);
|
||||||
}
|
}
|
||||||
}
|
};
|
||||||
|
Ok(value)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl ComputeSquaredDistance for AnimationValue {
|
impl ComputeSquaredDistance for AnimationValue {
|
||||||
fn compute_squared_distance(&self, other: &Self) -> Result<SquaredDistance, ()> {
|
fn compute_squared_distance(&self, other: &Self) -> Result<SquaredDistance, ()> {
|
||||||
|
match *self {
|
||||||
|
% for i, prop in enumerate([p for p in data.longhands if p.animatable and p.animation_value_type == "discrete"]):
|
||||||
|
% if i > 0:
|
||||||
|
|
|
||||||
|
% endif
|
||||||
|
AnimationValue::${prop.camel_case}(..)
|
||||||
|
% endfor
|
||||||
|
=> return Err(()),
|
||||||
|
_ => (),
|
||||||
|
}
|
||||||
match (self, other) {
|
match (self, other) {
|
||||||
% for prop in data.longhands:
|
% for prop in data.longhands:
|
||||||
% if prop.animatable:
|
% if prop.animatable:
|
||||||
|
@ -570,10 +585,6 @@ impl ComputeSquaredDistance for AnimationValue {
|
||||||
(&AnimationValue::${prop.camel_case}(ref this), &AnimationValue::${prop.camel_case}(ref other)) => {
|
(&AnimationValue::${prop.camel_case}(ref this), &AnimationValue::${prop.camel_case}(ref other)) => {
|
||||||
this.compute_squared_distance(other)
|
this.compute_squared_distance(other)
|
||||||
},
|
},
|
||||||
% else:
|
|
||||||
(&AnimationValue::${prop.camel_case}(_), &AnimationValue::${prop.camel_case}(_)) => {
|
|
||||||
Err(())
|
|
||||||
},
|
|
||||||
% endif
|
% endif
|
||||||
% endif
|
% endif
|
||||||
% endfor
|
% endfor
|
||||||
|
|
|
@ -40,6 +40,8 @@ packages = [
|
||||||
]
|
]
|
||||||
# Files that are ignored for all tidy and lint checks.
|
# Files that are ignored for all tidy and lint checks.
|
||||||
files = [
|
files = [
|
||||||
|
# Mako does not lend itself easily to splitting long lines
|
||||||
|
"./components/style/properties/helpers/animated_properties.mako.rs",
|
||||||
# Helper macro where actually a pseudo-element per line makes sense.
|
# Helper macro where actually a pseudo-element per line makes sense.
|
||||||
"./components/style/gecko/non_ts_pseudo_class_list.rs",
|
"./components/style/gecko/non_ts_pseudo_class_list.rs",
|
||||||
# Generated and upstream code combined with our own. Could use cleanup
|
# Generated and upstream code combined with our own. Could use cleanup
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue