Skip to content

Commit

Permalink
Implement PartialEq for AnimationValue by hand 馃悏馃惒
Browse files Browse the repository at this point in the history
We use the same trick as in PropertyDeclaration::eq.
  • Loading branch information
nox committed Feb 11, 2018
1 parent 2f4362e commit b95b6c6
Showing 1 changed file with 35 additions and 7 deletions.
42 changes: 35 additions & 7 deletions components/style/properties/helpers/animated_properties.mako.rs
Expand Up @@ -345,8 +345,8 @@ unsafe impl HasSimpleFFI for AnimationValueMap {}
///
/// FIXME: We need to add a path for custom properties, but that's trivial after
/// this (is a similar path to that of PropertyDeclaration).
#[derive(Clone, Debug, PartialEq)]
#[cfg_attr(feature = "servo", derive(MallocSizeOf))]
#[derive(Clone, Debug)]
#[repr(u16)]
pub enum AnimationValue {
% for prop in data.longhands:
Expand All @@ -370,6 +370,40 @@ pub enum AnimationValue {
unanimated.append(prop)
%>

#[repr(C)]
struct AnimationValueVariantRepr<T> {
tag: u16,
value: T
}

impl PartialEq for AnimationValue {
#[inline]
fn eq(&self, other: &Self) -> bool {
use self::AnimationValue::*;

unsafe {
let this_tag = *(self as *const _ as *const u16);
let other_tag = *(other as *const _ as *const u16);
if this_tag != other_tag {
return false;
}

match *self {
% for ty, props in groupby(animated, key=lambda x: x.animated_type()):
${" |\n".join("{}(ref this)".format(prop.camel_case) for prop in props)} => {
let other_repr =
&*(other as *const _ as *const AnimationValueVariantRepr<${ty}>);
*this == other_repr.value
}
% endfor
${" |\n".join("{}(void)".format(prop.camel_case) for prop in unanimated)} => {
void::unreachable(void)
}
}
}
}
}

impl AnimationValue {
/// Returns the longhand id this animated value corresponds to.
#[inline]
Expand Down Expand Up @@ -564,12 +598,6 @@ 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 {
fn animate(&self, other: &Self, procedure: Procedure) -> Result<Self, ()> {
Ok(unsafe {
Expand Down

0 comments on commit b95b6c6

Please sign in to comment.