From 752978837566d58ed2b14922d3b78618191c4795 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Emilio=20Cobos=20=C3=81lvarez?= Date: Mon, 4 Jun 2018 21:08:35 +0200 Subject: [PATCH] style: Make getting a property name explicitly an indexing operation. The six milliseconds spent in Olli's profile make me thing this is not getting optimized and we expected. Also move it to NonCustomPropertyId, so it works for aliases properly too. Bug: 1466645 Reviewed-by: xidorn MozReview-Commit-ID: 4d76Z55ZBEH --- .../style/properties/properties.mako.rs | 25 +++++++++++-------- 1 file changed, 15 insertions(+), 10 deletions(-) diff --git a/components/style/properties/properties.mako.rs b/components/style/properties/properties.mako.rs index 2c80c2573c8..e2078853844 100644 --- a/components/style/properties/properties.mako.rs +++ b/components/style/properties/properties.mako.rs @@ -428,6 +428,17 @@ impl NonCustomPropertyId { MAP[self.0] } + /// Get the property name. + #[inline] + fn name(self) -> &'static str { + static MAP: [&'static str; ${len(data.longhands) + len(data.shorthands) + len(data.all_aliases())}] = [ + % for property in data.longhands + data.shorthands + data.all_aliases(): + "${property.name}", + % endfor + ]; + MAP[self.0] + } + #[inline] fn enabled_for_all_content(self) -> bool { ${static_non_custom_property_id_set( @@ -860,12 +871,9 @@ impl fmt::Debug for LonghandId { impl LonghandId { /// Get the name of this longhand property. + #[inline] pub fn name(&self) -> &'static str { - match *self { - % for property in data.longhands: - LonghandId::${property.camel_case} => "${property.name}", - % endfor - } + NonCustomPropertyId::from(*self).name() } /// Returns whether the longhand property is inherited by default. @@ -1203,12 +1211,9 @@ impl ToCss for ShorthandId { impl ShorthandId { /// Get the name for this shorthand property. + #[inline] pub fn name(&self) -> &'static str { - match *self { - % for property in data.shorthands: - ShorthandId::${property.camel_case} => "${property.name}", - % endfor - } + NonCustomPropertyId::from(*self).name() } /// Converts from a ShorthandId to an adequate nsCSSPropertyID.