diff --git a/components/servo_arc/lib.rs b/components/servo_arc/lib.rs index ad4489c10bc..bd6b5289504 100644 --- a/components/servo_arc/lib.rs +++ b/components/servo_arc/lib.rs @@ -485,6 +485,14 @@ impl Arc { } } + /// Whether or not the `Arc` is a static reference. + #[inline] + pub fn is_static(&self) -> bool { + // Using a relaxed ordering to check for STATIC_REFCOUNT is safe, since + // `count` never changes between STATIC_REFCOUNT and other values. + self.inner().count.load(Relaxed) == STATIC_REFCOUNT + } + /// Whether or not the `Arc` is uniquely owned (is the refcount 1?) and not /// a static reference. #[inline] @@ -501,10 +509,7 @@ impl Drop for Arc { fn drop(&mut self) { // NOTE(emilio): If you change anything here, make sure that the // implementation in layout/style/ServoStyleConstsInlines.h matches! - // - // Using a relaxed ordering to check for STATIC_REFCOUNT is safe, since - // `count` never changes between STATIC_REFCOUNT and other values. - if self.inner().count.load(Relaxed) == STATIC_REFCOUNT { + if self.is_static() { return; } diff --git a/components/style/stylesheets/stylesheet.rs b/components/style/stylesheets/stylesheet.rs index 15c60402be4..f5194d7d443 100644 --- a/components/style/stylesheets/stylesheet.rs +++ b/components/style/stylesheets/stylesheet.rs @@ -124,6 +124,7 @@ impl StylesheetContents { url_data: UrlExtraData, quirks_mode: QuirksMode, ) -> Self { + debug_assert!(rules.is_static()); Self { rules, origin, @@ -144,6 +145,9 @@ impl StylesheetContents { /// Measure heap usage. #[cfg(feature = "gecko")] pub fn size_of(&self, guard: &SharedRwLockReadGuard, ops: &mut MallocSizeOfOps) -> usize { + if self.rules.is_static() { + return 0; + } // Measurement of other fields may be added later. self.rules.unconditional_shallow_size_of(ops) + self.rules.read_with(guard).size_of(guard, ops)