mirror of
https://github.com/servo/servo.git
synced 2025-08-03 12:40:06 +01:00
style: Share CascadeData instances across ShadowRoots
This should be both a memory and speed win for pages using a lot of Shadow DOM. In order to make the cache properly work we need to start keying media query results on the actual StyleSheetContents, as that's what we share on Gecko, but that should all be fine. Differential Revision: https://phabricator.services.mozilla.com/D107266
This commit is contained in:
parent
11153c63fa
commit
060d74ba3b
11 changed files with 175 additions and 178 deletions
|
@ -4,7 +4,6 @@
|
|||
|
||||
//! Data needed to style a Gecko document.
|
||||
|
||||
use crate::context::QuirksMode;
|
||||
use crate::dom::TElement;
|
||||
use crate::gecko_bindings::bindings;
|
||||
use crate::gecko_bindings::structs::{self, RawServoStyleSet, ServoStyleSetSizes};
|
||||
|
@ -15,7 +14,7 @@ use crate::media_queries::{Device, MediaList};
|
|||
use crate::properties::ComputedValues;
|
||||
use crate::selector_parser::SnapshotMap;
|
||||
use crate::shared_lock::{Locked, SharedRwLockReadGuard, StylesheetGuards};
|
||||
use crate::stylesheets::{CssRule, Origin, StylesheetContents, StylesheetInDocument};
|
||||
use crate::stylesheets::{StylesheetContents, StylesheetInDocument};
|
||||
use crate::stylist::Stylist;
|
||||
use atomic_refcell::{AtomicRef, AtomicRefCell, AtomicRefMut};
|
||||
use malloc_size_of::MallocSizeOfOps;
|
||||
|
@ -69,16 +68,6 @@ impl GeckoStyleSheet {
|
|||
fn inner(&self) -> &StyleSheetInfo {
|
||||
unsafe { &*(self.raw().mInner as *const StyleSheetInfo) }
|
||||
}
|
||||
|
||||
/// Gets the StylesheetContents for this stylesheet.
|
||||
pub fn contents(&self) -> &StylesheetContents {
|
||||
debug_assert!(!self.inner().mContents.mRawPtr.is_null());
|
||||
unsafe {
|
||||
let contents =
|
||||
(&**StylesheetContents::as_arc(&&*self.inner().mContents.mRawPtr)) as *const _;
|
||||
&*contents
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl Drop for GeckoStyleSheet {
|
||||
|
@ -95,14 +84,6 @@ impl Clone for GeckoStyleSheet {
|
|||
}
|
||||
|
||||
impl StylesheetInDocument for GeckoStyleSheet {
|
||||
fn origin(&self, _guard: &SharedRwLockReadGuard) -> Origin {
|
||||
self.contents().origin
|
||||
}
|
||||
|
||||
fn quirks_mode(&self, _guard: &SharedRwLockReadGuard) -> QuirksMode {
|
||||
self.contents().quirks_mode
|
||||
}
|
||||
|
||||
fn media<'a>(&'a self, guard: &'a SharedRwLockReadGuard) -> Option<&'a MediaList> {
|
||||
use crate::gecko_bindings::structs::mozilla::dom::MediaList as DomMediaList;
|
||||
use std::mem;
|
||||
|
@ -120,13 +101,19 @@ impl StylesheetInDocument for GeckoStyleSheet {
|
|||
|
||||
// All the stylesheets Servo knows about are enabled, because that state is
|
||||
// handled externally by Gecko.
|
||||
#[inline]
|
||||
fn enabled(&self) -> bool {
|
||||
true
|
||||
}
|
||||
|
||||
#[inline]
|
||||
fn rules<'a, 'b: 'a>(&'a self, guard: &'b SharedRwLockReadGuard) -> &'a [CssRule] {
|
||||
self.contents().rules(guard)
|
||||
fn contents(&self) -> &StylesheetContents {
|
||||
debug_assert!(!self.inner().mContents.mRawPtr.is_null());
|
||||
unsafe {
|
||||
let contents =
|
||||
(&**StylesheetContents::as_arc(&&*self.inner().mContents.mRawPtr)) as *const _;
|
||||
&*contents
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue