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
--- 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()
}