mirror of
https://github.com/servo/servo.git
synced 2025-08-03 20:50:07 +01:00
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
This commit is contained in:
parent
89b8f30737
commit
4f04988c13
2 changed files with 22 additions and 5 deletions
|
@ -1863,7 +1863,8 @@ impl PropertyId {
|
|||
}
|
||||
}
|
||||
|
||||
fn non_custom_id(&self) -> Option<NonCustomPropertyId> {
|
||||
/// Returns the `NonCustomPropertyId` corresponding to this property id.
|
||||
pub fn non_custom_id(&self) -> Option<NonCustomPropertyId> {
|
||||
Some(match *self {
|
||||
PropertyId::Custom(_) => return None,
|
||||
PropertyId::Shorthand(shorthand_id) => shorthand_id.into(),
|
||||
|
|
|
@ -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
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue