mirror of
https://github.com/servo/servo.git
synced 2025-08-05 13:40:08 +01:00
Merge similar arms in AnimationValue::compute_squared_distance 🐉🐲
This uses the same trick as in PropertyDeclaration::eq.
This commit is contained in:
parent
fc24cf34c5
commit
b9505ae72b
1 changed files with 34 additions and 30 deletions
|
@ -564,16 +564,16 @@ fn animate_discrete<T: Clone>(this: &T, other: &T, procedure: Procedure) -> Resu
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[repr(C)]
|
||||||
|
struct AnimationValueVariantRepr<T> {
|
||||||
|
tag: u16,
|
||||||
|
value: T
|
||||||
|
}
|
||||||
|
|
||||||
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, ()> {
|
||||||
use self::AnimationValue::*;
|
|
||||||
|
|
||||||
Ok(unsafe {
|
Ok(unsafe {
|
||||||
#[repr(C)]
|
use self::AnimationValue::*;
|
||||||
struct AnimationValueVariantRepr<T> {
|
|
||||||
tag: u16,
|
|
||||||
value: T
|
|
||||||
}
|
|
||||||
|
|
||||||
let this_tag = *(self as *const _ as *const u16);
|
let this_tag = *(self as *const _ as *const u16);
|
||||||
let other_tag = *(other as *const _ as *const u16);
|
let other_tag = *(other as *const _ as *const u16);
|
||||||
|
@ -612,31 +612,35 @@ impl Animate for AnimationValue {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
<%
|
||||||
|
nondiscrete = []
|
||||||
|
for prop in animated:
|
||||||
|
if prop.animation_value_type != "discrete":
|
||||||
|
nondiscrete.append(prop)
|
||||||
|
%>
|
||||||
|
|
||||||
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 {
|
unsafe {
|
||||||
% for i, prop in enumerate([p for p in data.longhands if p.animatable and p.animation_value_type == "discrete"]):
|
use self::AnimationValue::*;
|
||||||
% if i > 0:
|
|
||||||
|
|
let this_tag = *(self as *const _ as *const u16);
|
||||||
% endif
|
let other_tag = *(other as *const _ as *const u16);
|
||||||
AnimationValue::${prop.camel_case}(..)
|
if this_tag != other_tag {
|
||||||
% endfor
|
panic!("Unexpected AnimationValue::compute_squared_distance call");
|
||||||
=> return Err(()),
|
}
|
||||||
_ => (),
|
|
||||||
}
|
match *self {
|
||||||
match (self, other) {
|
% for ty, props in groupby(nondiscrete, key=lambda x: x.animated_type()):
|
||||||
% for prop in data.longhands:
|
${" |\n".join("{}(ref this)".format(prop.camel_case) for prop in props)} => {
|
||||||
% if prop.animatable:
|
let other_repr =
|
||||||
% if prop.animation_value_type != "discrete":
|
&*(other as *const _ as *const AnimationValueVariantRepr<${ty}>);
|
||||||
(&AnimationValue::${prop.camel_case}(ref this), &AnimationValue::${prop.camel_case}(ref other)) => {
|
|
||||||
this.compute_squared_distance(other)
|
this.compute_squared_distance(&other_repr.value)
|
||||||
},
|
}
|
||||||
% endif
|
% endfor
|
||||||
% endif
|
_ => Err(()),
|
||||||
% endfor
|
}
|
||||||
_ => {
|
|
||||||
panic!("computed values should be of the same property");
|
|
||||||
},
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue