Bug 1630837 - Optimize CC of rules from constructable stylesheets. r=smaug,nordzilla

This removes StyleSheet::GetComposedDoc because it wasn't doing the
right thing, and while constructable stylesheets _could_ in theory
return something meaningful (the constructor doc iff any adopters is
connected), it's not a concept we need in other places for now.

Differential Revision: https://phabricator.services.mozilla.com/D71261
This commit is contained in:
Emilio Cobos Álvarez 2020-04-17 21:12:11 +00:00
Родитель ece4eed6d3
Коммит 1f3abc7835
4 изменённых файлов: 51 добавлений и 53 удалений

Просмотреть файл

@ -44,12 +44,9 @@ bool Rule::IsKnownLive() const {
return false;
}
if (!sheet->IsKeptAliveByDocument()) {
return false;
}
return nsCCUncollectableMarker::InGeneration(
GetComposedDoc()->GetMarkedCCGeneration());
Document* doc = sheet->GetKeptAliveByDocument();
return doc &&
nsCCUncollectableMarker::InGeneration(doc->GetMarkedCCGeneration());
}
void Rule::UnlinkDeclarationWrapper(nsWrapperCache& aDecl) {

Просмотреть файл

@ -68,13 +68,6 @@ class Rule : public nsISupports, public nsWrapperCache {
StyleSheet* GetStyleSheet() const { return mSheet; }
// Return the document the rule applies to, if any.
//
// Suitable for style updates, and that's about it.
dom::Document* GetComposedDoc() const {
return mSheet ? mSheet->GetComposedDoc() : nullptr;
}
// Clear the mSheet pointer on this rule and descendants.
virtual void DropSheetReference();

Просмотреть файл

@ -175,18 +175,25 @@ dom::DocumentOrShadowRoot* StyleSheet::GetAssociatedDocumentOrShadowRoot()
return nullptr;
}
Document* StyleSheet::GetComposedDoc() const {
return mDocumentOrShadowRoot
? mDocumentOrShadowRoot->AsNode().GetComposedDoc()
: nullptr;
}
bool StyleSheet::IsKeptAliveByDocument() const {
if (mAssociationMode != OwnedByDocumentOrShadowRoot) {
return false;
Document* StyleSheet::GetKeptAliveByDocument() const {
// TODO(emilio): Now that we're doing parent walks for both this and
// GetAssociatedDocument(), seems we could simplify the association code not
// to be propagated to children.
if (mAssociationMode == OwnedByDocumentOrShadowRoot) {
MOZ_ASSERT(mDocumentOrShadowRoot);
return mDocumentOrShadowRoot->AsNode().GetComposedDoc();
}
return !!GetComposedDoc();
for (const auto* sheet = this; sheet; sheet = sheet->mParentSheet) {
if (sheet->IsConstructed()) {
for (DocumentOrShadowRoot* adopter : sheet->mAdopters) {
MOZ_ASSERT(adopter->AsNode().OwnerDoc() == sheet->mConstructorDocument);
if (adopter->AsNode().IsInComposedDoc()) {
return sheet->mConstructorDocument.get();
}
}
}
}
return nullptr;
}
void StyleSheet::LastRelease() {
@ -491,28 +498,32 @@ void StyleSheet::DropStyleSet(ServoStyleSet* aStyleSet) {
// NOTE(emilio): Composed doc and containing shadow root are set in child sheets
// too, so no need to do it for each ancestor.
#define NOTIFY(function_, args_) \
do { \
if (auto* shadow = GetContainingShadow()) { \
shadow->function_ args_; \
} \
if (auto* doc = GetComposedDoc()) { \
doc->function_ args_; \
} \
StyleSheet* current = this; \
do { \
for (ServoStyleSet * set : current->mStyleSets) { \
set->function_ args_; \
} \
for (auto* adopter : mAdopters) { \
if (auto* shadow = ShadowRoot::FromNode(adopter->AsNode())) { \
shadow->function_ args_; \
} else { \
adopter->AsNode().AsDocument()->function_ args_; \
} \
} \
current = current->mParentSheet; \
} while (current); \
#define NOTIFY(function_, args_) \
do { \
if (auto* shadow = GetContainingShadow()) { \
shadow->function_ args_; \
} \
/* FIXME(emilio, bug 1630835): This should probably do something \
* for constructed sheets, at least for some notifications. */ \
if (mDocumentOrShadowRoot) { \
if (auto* doc = mDocumentOrShadowRoot->AsNode().GetComposedDoc()) { \
doc->function_ args_; \
} \
} \
StyleSheet* current = this; \
do { \
for (ServoStyleSet * set : current->mStyleSets) { \
set->function_ args_; \
} \
for (auto* adopter : mAdopters) { \
if (auto* shadow = ShadowRoot::FromNode(adopter->AsNode())) { \
shadow->function_ args_; \
} else { \
adopter->AsNode().AsDocument()->function_ args_; \
} \
} \
current = current->mParentSheet; \
} while (current); \
} while (0)
void StyleSheet::EnsureUniqueInner() {

Просмотреть файл

@ -255,13 +255,10 @@ class StyleSheet final : public nsICSSLoaderObserver, public nsWrapperCache {
};
dom::DocumentOrShadowRoot* GetAssociatedDocumentOrShadowRoot() const;
// Whether this stylesheet is kept alive by the associated document or
// associated shadow root's document somehow, and thus at least has the same
// lifetime as GetAssociatedDocument().
bool IsKeptAliveByDocument() const;
// Returns the document whose styles this sheet is affecting.
dom::Document* GetComposedDoc() const;
// Whether this stylesheet is kept alive by the associated or constructor
// document somehow, and thus at least has the same lifetime as
// GetAssociatedDocument().
dom::Document* GetKeptAliveByDocument() const;
// If this is a constructed style sheet, return mConstructorDocument.
// Otherwise return the document we're associated to,