From e2c674994a3cbf32e9046df06e354f7ce3cf0111 Mon Sep 17 00:00:00 2001 From: Anthony Ramine Date: Sun, 11 Feb 2018 15:54:31 +0100 Subject: [PATCH] Use ascii_case_insensitive_phf_map in TransitionProperty::parse This divides the size of this method by 30. --- .../helpers/animated_properties.mako.rs | 46 +++++++++++++------ 1 file changed, 33 insertions(+), 13 deletions(-) diff --git a/components/style/properties/helpers/animated_properties.mako.rs b/components/style/properties/helpers/animated_properties.mako.rs index ad64c3e7224..281d9c53fb3 100644 --- a/components/style/properties/helpers/animated_properties.mako.rs +++ b/components/style/properties/helpers/animated_properties.mako.rs @@ -24,7 +24,6 @@ use properties::longhands::visibility::computed_value::T as Visibility; #[cfg(feature = "gecko")] use properties::PropertyId; use properties::{LonghandId, ShorthandId}; -use selectors::parser::SelectorParseErrorKind; use servo_arc::Arc; use smallvec::SmallVec; use std::{cmp, ptr}; @@ -142,21 +141,42 @@ impl TransitionProperty { /// Parse a transition-property value. pub fn parse<'i, 't>(input: &mut Parser<'i, 't>) -> Result> { + // FIXME(https://github.com/rust-lang/rust/issues/33156): remove this + // enum and use PropertyId when stable Rust allows destructors in + // statics. + // + // FIXME: This should handle aliases too. + pub enum StaticId { + All, + Longhand(LonghandId), + Shorthand(ShorthandId), + } + ascii_case_insensitive_phf_map! { + static_id -> StaticId = { + "all" => StaticId::All, + % for prop in data.shorthands_except_all(): + "${prop.name}" => StaticId::Shorthand(ShorthandId::${prop.camel_case}), + % endfor + % for prop in data.longhands: + "${prop.name}" => StaticId::Longhand(LonghandId::${prop.camel_case}), + % endfor + } + } + let location = input.current_source_location(); let ident = input.expect_ident()?; - match_ignore_ascii_case! { &ident, - "all" => Ok(TransitionProperty::All), - % for prop in data.shorthands_except_all(): - "${prop.name}" => Ok(TransitionProperty::Shorthand(ShorthandId::${prop.camel_case})), - % endfor - % for prop in data.longhands: - "${prop.name}" => Ok(TransitionProperty::Longhand(LonghandId::${prop.camel_case})), - % endfor - "none" => Err(location.new_custom_error(SelectorParseErrorKind::UnexpectedIdent(ident.clone()))), - _ => CustomIdent::from_ident(location, ident, &[]).map(TransitionProperty::Unsupported), - } - } + Ok(match static_id(&ident) { + Some(&StaticId::All) => TransitionProperty::All, + Some(&StaticId::Longhand(id)) => TransitionProperty::Longhand(id), + Some(&StaticId::Shorthand(id)) => TransitionProperty::Shorthand(id), + None => { + TransitionProperty::Unsupported( + CustomIdent::from_ident(location, ident, &["none"])?, + ) + }, + }) + } /// Convert TransitionProperty to nsCSSPropertyID. #[cfg(feature = "gecko")]