Bug 1466645: Make getting a property name explicitly an indexing operation. r?xidorn draft
authorEmilio Cobos Álvarez <emilio@crisal.io>
Mon, 04 Jun 2018 21:08:35 +0200
changeset 804322 11efb6ce849c9dd0d38b38e7d8a06742041e724c
parent 804321 8dc732da7da4a5fcdd2786376c979e548acc02a3
child 804323 b3c86fc7e7870868df0344dba7db08c3c5dfbe86
push id112345
push userbmo:emilio@crisal.io
push dateTue, 05 Jun 2018 19:10:58 +0000
reviewersxidorn
bugs1466645
milestone62.0a1
Bug 1466645: Make getting a property name explicitly an indexing operation. r?xidorn 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. MozReview-Commit-ID: 4d76Z55ZBEH
servo/components/style/properties/properties.mako.rs
--- a/servo/components/style/properties/properties.mako.rs
+++ b/servo/components/style/properties/properties.mako.rs
@@ -423,16 +423,27 @@ impl NonCustomPropertyId {
             % for property in data.longhands + data.shorthands + data.all_aliases():
                 ${property.nscsspropertyid()},
             % endfor
         ];
 
         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(
             "EXPERIMENTAL",
             lambda p: p.experimental(product)
         )}
 
         ${static_non_custom_property_id_set(
@@ -855,22 +866,19 @@ impl ToCss for LonghandId {
 impl fmt::Debug for LonghandId {
     fn fmt(&self, formatter: &mut fmt::Formatter) -> fmt::Result {
         formatter.write_str(self.name())
     }
 }
 
 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.
     pub fn inherited(&self) -> bool {
         ${static_longhand_id_set("INHERITED", lambda p: p.style_struct.inherited)}
         INHERITED.contains(*self)
     }
 
@@ -1198,22 +1206,19 @@ impl ToCss for ShorthandId {
         W: Write,
     {
         dest.write_str(self.name())
     }
 }
 
 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.
     #[cfg(feature = "gecko")]
     #[inline]
     pub fn to_nscsspropertyid(self) -> nsCSSPropertyID {
         NonCustomPropertyId::from(self).to_nscsspropertyid()
     }