mirror of
https://github.com/servo/servo.git
synced 2025-08-07 06:25:32 +01:00
style: Cache computed styles objects display: none subtrees
This reuses our existing undisplayed style generation, but in a per-document rather than per-nsComputedDOMStyle object, which means that we can avoid re-resolving styles of elements in display: none subtrees much more often. This brings the test-case in the bug to par with other browsers or better, and is much simpler than the initial approach I tried back in the day. Differential Revision: https://phabricator.services.mozilla.com/D147547
This commit is contained in:
parent
39ac4840ee
commit
d1aeb3921b
3 changed files with 46 additions and 9 deletions
|
@ -129,6 +129,12 @@ impl StylesheetInDocument for GeckoStyleSheet {
|
|||
pub struct PerDocumentStyleDataImpl {
|
||||
/// Rule processor.
|
||||
pub stylist: Stylist,
|
||||
|
||||
/// A cache from element to resolved style.
|
||||
pub undisplayed_style_cache: crate::traversal::UndisplayedStyleCache,
|
||||
|
||||
/// The generation for which our cache is valid.
|
||||
pub undisplayed_style_cache_generation: u64,
|
||||
}
|
||||
|
||||
/// The data itself is an `AtomicRefCell`, which guarantees the proper semantics
|
||||
|
@ -143,6 +149,8 @@ impl PerDocumentStyleData {
|
|||
|
||||
PerDocumentStyleData(AtomicRefCell::new(PerDocumentStyleDataImpl {
|
||||
stylist: Stylist::new(device, quirks_mode.into()),
|
||||
undisplayed_style_cache: Default::default(),
|
||||
undisplayed_style_cache_generation: 0,
|
||||
}))
|
||||
}
|
||||
|
||||
|
@ -177,12 +185,6 @@ impl PerDocumentStyleDataImpl {
|
|||
self.stylist.device().default_computed_values_arc()
|
||||
}
|
||||
|
||||
/// Returns whether visited styles are enabled.
|
||||
#[inline]
|
||||
pub fn visited_styles_enabled(&self) -> bool {
|
||||
unsafe { bindings::Gecko_VisitedStylesEnabled(self.stylist.device().document()) }
|
||||
}
|
||||
|
||||
/// Measure heap usage.
|
||||
pub fn add_size_of(&self, ops: &mut MallocSizeOfOps, sizes: &mut ServoStyleSetSizes) {
|
||||
self.stylist.add_size_of(ops, sizes);
|
||||
|
|
|
@ -411,6 +411,11 @@ impl Device {
|
|||
self.used_font_metrics.load(Ordering::Relaxed)
|
||||
}
|
||||
|
||||
/// Returns whether visited styles are enabled.
|
||||
pub fn visited_styles_enabled(&self) -> bool {
|
||||
unsafe { bindings::Gecko_VisitedStylesEnabled(self.document()) }
|
||||
}
|
||||
|
||||
/// Returns the device pixel ratio.
|
||||
pub fn device_pixel_ratio(&self) -> Scale<f32, CSSPixel, DevicePixel> {
|
||||
let pc = match self.pres_context() {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue