From 921d1aeebada477a8ebe35b75e44e9dbecae8842 Mon Sep 17 00:00:00 2001 From: Anthony Ramine Date: Fri, 9 Feb 2018 22:54:33 +0100 Subject: [PATCH] =?UTF-8?q?Make=20AnimationValue::id=20be=20just=20a=20poi?= =?UTF-8?q?nter=20cast=20=F0=9F=90=89=F0=9F=90=B2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Now that PropertyDeclaration and AnimationValue have the same discriminants, that means the trick found in PropertyDeclaration::id can be done in AnimationValue::id. --- components/malloc_size_of/lib.rs | 2 +- .../style/properties/helpers/animated_properties.mako.rs | 6 ++++-- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/components/malloc_size_of/lib.rs b/components/malloc_size_of/lib.rs index 3801669ab5d..5e97a2709dc 100644 --- a/components/malloc_size_of/lib.rs +++ b/components/malloc_size_of/lib.rs @@ -58,9 +58,9 @@ extern crate smallvec; extern crate string_cache; #[cfg(feature = "url")] extern crate url; +extern crate void; #[cfg(feature = "webrender_api")] extern crate webrender_api; -extern crate void; #[cfg(feature = "servo")] extern crate xml5ever; diff --git a/components/style/properties/helpers/animated_properties.mako.rs b/components/style/properties/helpers/animated_properties.mako.rs index 703b6be9fe5..a5f1abd935e 100644 --- a/components/style/properties/helpers/animated_properties.mako.rs +++ b/components/style/properties/helpers/animated_properties.mako.rs @@ -364,7 +364,8 @@ pub enum AnimationValue { impl AnimationValue { /// Returns the longhand id this animated value corresponds to. pub fn id(&self) -> LonghandId { - match *self { + let id = unsafe { *(self as *const _ as *const LonghandId) }; + debug_assert_eq!(id, match *self { % for prop in data.longhands: % if prop.animatable: AnimationValue::${prop.camel_case}(..) => LonghandId::${prop.camel_case}, @@ -372,7 +373,8 @@ impl AnimationValue { AnimationValue::${prop.camel_case}(void) => void::unreachable(void), % endif % endfor - } + }); + id } /// "Uncompute" this animation value in order to be used inside the CSS