From 22da3c22a2751ac2de4a0dffcad171ab26a6a59e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Emilio=20Cobos=20=C3=81lvarez?= Date: Tue, 18 Sep 2018 09:15:12 +0000 Subject: [PATCH] style: Make LonghandId::flags an indexing operation. I always see a bunch of time in our profiles in the iterator over the declarations, this ensures it's not something dumb. I suspect it's just a bunch of cache misses from walking the rule tree but in any case this is consistent with the other getters we have and such. Differential Revision: https://phabricator.services.mozilla.com/D5971 --- .../style/properties/properties.mako.rs | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/components/style/properties/properties.mako.rs b/components/style/properties/properties.mako.rs index 3ab358524ba..5968d84bd33 100644 --- a/components/style/properties/properties.mako.rs +++ b/components/style/properties/properties.mako.rs @@ -1113,16 +1113,19 @@ impl LonghandId { } /// Returns PropertyFlags for given longhand property. - pub fn flags(&self) -> PropertyFlags { - match *self { + #[inline(always)] + pub fn flags(self) -> PropertyFlags { + // TODO(emilio): This can be simplified further as Rust gains more + // constant expression support. + const FLAGS: [u8; ${len(data.longhands)}] = [ % for property in data.longhands: - LonghandId::${property.camel_case} => - % for flag in property.flags: - PropertyFlags::${flag} | - % endfor - PropertyFlags::empty(), + % for flag in property.flags: + PropertyFlags::${flag}.bits | + % endfor + 0, % endfor - } + ]; + PropertyFlags::from_bits_truncate(FLAGS[self as usize]) } /// Only a few properties are allowed to depend on the visited state of