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

@ -167,15 +167,14 @@ impl<'lr> TShadowRoot for GeckoShadowRoot<'lr> {
}
#[inline]
fn style_data<'a>(&self) -> &'a CascadeData
fn style_data<'a>(&self) -> Option<&'a CascadeData>
where
Self: 'a,
{
debug_assert!(!self.0.mServoStyles.mPtr.is_null());
let author_styles = unsafe {
&*(self.0.mServoStyles.mPtr as *const structs::RawServoAuthorStyles
as *const bindings::RawServoAuthorStyles)
(self.0.mServoStyles.mPtr
as *const structs::RawServoAuthorStyles
as *const bindings::RawServoAuthorStyles).as_ref()?
};
@ -187,7 +186,7 @@ impl<'lr> TShadowRoot for GeckoShadowRoot<'lr> {
author_styles.stylesheets.dirty()
);
&author_styles.data
Some(&author_styles.data)
}
#[inline]