style: Make the allocation of AuthorStyles for ShadowRoot lazy.

So that we don't waste a bunch of memory with stuff like <svg:use>. I
plan to shrink AuthorStyles further, but this should help regardless, and isn't
very complex.

Differential Revision: https://phabricator.services.mozilla.com/D4618
This commit is contained in:
Emilio Cobos Álvarez 2018-08-30 12:00:00 +00:00
parent 1bc452703b
commit 1e6aa62c6f
No known key found for this signature in database
GPG key ID: 056B727BB9C1027C
3 changed files with 41 additions and 28 deletions

View file

@ -342,7 +342,7 @@ pub trait TShadowRoot: Sized + Copy + Clone + PartialEq {
fn host(&self) -> <Self::ConcreteNode as TNode>::ConcreteElement;
/// Get the style data for this ShadowRoot.
fn style_data<'a>(&self) -> &'a CascadeData
fn style_data<'a>(&self) -> Option<&'a CascadeData>
where
Self: 'a;
@ -824,30 +824,36 @@ pub trait TElement:
if let Some(shadow) = self.containing_shadow() {
doc_rules_apply = false;
f(
shadow.style_data(),
self.as_node().owner_doc().quirks_mode(),
Some(shadow.host()),
);
if let Some(data) = shadow.style_data() {
f(
data,
self.as_node().owner_doc().quirks_mode(),
Some(shadow.host()),
);
}
}
if let Some(shadow) = self.shadow_root() {
f(
shadow.style_data(),
self.as_node().owner_doc().quirks_mode(),
Some(shadow.host()),
);
if let Some(data) = shadow.style_data() {
f(
data,
self.as_node().owner_doc().quirks_mode(),
Some(shadow.host()),
);
}
}
let mut current = self.assigned_slot();
while let Some(slot) = current {
// Slots can only have assigned nodes when in a shadow tree.
let shadow = slot.containing_shadow().unwrap();
f(
shadow.style_data(),
self.as_node().owner_doc().quirks_mode(),
Some(shadow.host()),
);
if let Some(data) = shadow.style_data() {
f(
data,
self.as_node().owner_doc().quirks_mode(),
Some(shadow.host()),
);
}
current = slot.assigned_slot();
}