Merge similar arms in AnimationValue::uncompute 🐉🐲

This uses the same kind of trick as PropertyDeclaration::clone and
removes 15KB off of libxul according to bloaty.
This commit is contained in:
Anthony Ramine 2018-02-10 03:17:45 +01:00
parent aa7cc261f8
commit 38520af970

View file

@ -27,7 +27,7 @@ use properties::{LonghandId, ShorthandId};
use selectors::parser::SelectorParseErrorKind; use selectors::parser::SelectorParseErrorKind;
use servo_arc::Arc; use servo_arc::Arc;
use smallvec::SmallVec; use smallvec::SmallVec;
use std::cmp; use std::{cmp, mem, ptr};
use std::fmt::{self, Write}; use std::fmt::{self, Write};
#[cfg(feature = "gecko")] use hash::FnvHashMap; #[cfg(feature = "gecko")] use hash::FnvHashMap;
use style_traits::{CssWriter, ParseError, ToCss}; use style_traits::{CssWriter, ParseError, ToCss};
@ -360,6 +360,16 @@ pub enum AnimationValue {
% endfor % endfor
} }
<%
animated = []
unanimated = []
for prop in data.longhands:
if prop.animatable:
animated.append(prop)
else:
unanimated.append(prop)
%>
impl AnimationValue { impl AnimationValue {
/// Returns the longhand id this animated value corresponds to. /// Returns the longhand id this animated value corresponds to.
#[inline] #[inline]
@ -381,29 +391,42 @@ impl AnimationValue {
/// cascade. /// cascade.
pub fn uncompute(&self) -> PropertyDeclaration { pub fn uncompute(&self) -> PropertyDeclaration {
use properties::longhands; use properties::longhands;
use self::AnimationValue::*;
use super::PropertyDeclarationVariantRepr;
match *self { match *self {
% for prop in data.longhands: <% keyfunc = lambda x: (x.base_type(), x.specified_type(), x.boxed, x.is_animatable_with_computed_value) %>
% if prop.animatable: % for (ty, specified, boxed, computed), props in groupby(animated, key=keyfunc):
AnimationValue::${prop.camel_case}(ref from) => { <% props = list(props) %>
PropertyDeclaration::${prop.camel_case}( ${" |\n".join("{}(ref value)".format(prop.camel_case) for prop in props)} => {
% if prop.boxed: % if not computed:
Box::new( let ref value = ToAnimatedValue::from_animated_value(value.clone());
% endif % endif
longhands::${prop.ident}::SpecifiedValue::from_computed_value( let value = ${ty}::from_computed_value(&value);
% if prop.is_animatable_with_computed_value: % if boxed:
from let value = Box::new(value);
% endif
% if len(props) == 1:
PropertyDeclaration::${props[0].camel_case}(value)
% else: % else:
&ToAnimatedValue::from_animated_value(from.clone()) unsafe {
% endif let mut out = mem::uninitialized();
)) ptr::write(
% if prop.boxed: &mut out as *mut _ as *mut PropertyDeclarationVariantRepr<${specified}>,
) PropertyDeclarationVariantRepr {
tag: *(self as *const _ as *const u16),
value,
},
);
out
}
% endif % endif
} }
% else:
AnimationValue::${prop.camel_case}(void) => void::unreachable(void),
% endif
% endfor % endfor
${" |\n".join("{}(void)".format(prop.camel_case) for prop in unanimated)} => {
void::unreachable(void)
}
} }
} }