From 4f04988c1373b9e14e407d8682407165aad03b98 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Emilio=20Cobos=20=C3=81lvarez?= Date: Mon, 20 Aug 2018 22:07:19 +0200 Subject: [PATCH] style: Add a test for the use counters. Mostly testing that they work, and that they record what we expect them to record, that is, the actual property that was parsed, and not the properties that it'd resolve or expand to. That may be another tricky part for CSSOM, I think style setters would fail an alias test if implemented with the current setup (we do the property lookup in C++). Differential Revision: https://phabricator.services.mozilla.com/D3829 --- .../style/properties/properties.mako.rs | 3 ++- components/style/use_counters/mod.rs | 24 +++++++++++++++---- 2 files changed, 22 insertions(+), 5 deletions(-) diff --git a/components/style/properties/properties.mako.rs b/components/style/properties/properties.mako.rs index 95f2504fe66..681e9556653 100644 --- a/components/style/properties/properties.mako.rs +++ b/components/style/properties/properties.mako.rs @@ -1863,7 +1863,8 @@ impl PropertyId { } } - fn non_custom_id(&self) -> Option { + /// Returns the `NonCustomPropertyId` corresponding to this property id. + pub fn non_custom_id(&self) -> Option { Some(match *self { PropertyId::Custom(_) => return None, PropertyId::Shorthand(shorthand_id) => shorthand_id.into(), diff --git a/components/style/use_counters/mod.rs b/components/style/use_counters/mod.rs index 68f04da64a0..03fdc045365 100644 --- a/components/style/use_counters/mod.rs +++ b/components/style/use_counters/mod.rs @@ -22,13 +22,29 @@ pub struct NonCustomPropertyUseCounters { } impl NonCustomPropertyUseCounters { - /// Record that a given non-custom property ID has been parsed. - #[inline] - pub fn record(&self, id: NonCustomPropertyId) { + /// Returns the bucket a given property belongs in, and the bitmask for that + /// property. + #[inline(always)] + fn bucket_and_pattern(id: NonCustomPropertyId) -> (usize, usize) { let bit = id.bit(); let bucket = bit / BITS_PER_ENTRY; let bit_in_bucket = bit % BITS_PER_ENTRY; - self.storage[bucket].fetch_or(1 << bit_in_bucket, Ordering::Relaxed); + (bucket, 1 << bit_in_bucket) + } + + /// Record that a given non-custom property ID has been parsed. + #[inline] + pub fn record(&self, id: NonCustomPropertyId) { + let (bucket, pattern) = Self::bucket_and_pattern(id); + self.storage[bucket].fetch_or(pattern, Ordering::Relaxed); + } + + /// Returns whether a given non-custom property ID has been recorded + /// earlier. + #[inline] + pub fn recorded(&self, id: NonCustomPropertyId) -> bool { + let (bucket, pattern) = Self::bucket_and_pattern(id); + self.storage[bucket].load(Ordering::Relaxed) & pattern != 0 } }