Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1199)

Unified Diff: third_party/WebKit/Source/core/dom/StyleEngine.cpp

Issue 2205843003: Use weak members to cache StyleSheetContents. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Might be in cache without being used before garbage collection Created 4 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: third_party/WebKit/Source/core/dom/StyleEngine.cpp
diff --git a/third_party/WebKit/Source/core/dom/StyleEngine.cpp b/third_party/WebKit/Source/core/dom/StyleEngine.cpp
index f739839f9b39e6d90d334df236eb63c7d8c3ba62..a5fb3f8c7d5933fb1afeddb52218f55d312c65da 100644
--- a/third_party/WebKit/Source/core/dom/StyleEngine.cpp
+++ b/third_party/WebKit/Source/core/dom/StyleEngine.cpp
@@ -511,18 +511,20 @@ CSSStyleSheet* StyleEngine::createSheet(Element* e, const String& text, TextPosi
AtomicString textContent(text);
- HeapHashMap<AtomicString, Member<StyleSheetContents>>::AddResult result = m_textToSheetCache.add(textContent, nullptr);
- if (result.isNewEntry || !result.storedValue->value) {
+ auto result = m_textToSheetCache.add(textContent, nullptr);
+ StyleSheetContents* contents = result.storedValue->value;
+ if (result.isNewEntry || !contents || !contents->isCacheableForStyleElement()) {
+ result.storedValue->value = nullptr;
styleSheet = StyleEngine::parseSheet(e, text, startPosition);
- if (result.isNewEntry && styleSheet->contents()->isCacheableForStyleElement()) {
+ if (styleSheet->contents()->isCacheableForStyleElement()) {
result.storedValue->value = styleSheet->contents();
m_sheetToTextCache.add(styleSheet->contents(), textContent);
}
} else {
- StyleSheetContents* contents = result.storedValue->value;
DCHECK(contents);
DCHECK(contents->isCacheableForStyleElement());
- DCHECK_EQ(contents->singleOwnerDocument(), e->document());
+ DCHECK(contents->hasSingleOwnerDocument());
+ contents->setIsUsedFromTextCache();
styleSheet = CSSStyleSheet::createInline(contents, e, startPosition);
}
@@ -541,16 +543,6 @@ CSSStyleSheet* StyleEngine::parseSheet(Element* e, const String& text, TextPosit
return styleSheet;
}
-void StyleEngine::removeSheet(StyleSheetContents* contents)
-{
- HeapHashMap<Member<StyleSheetContents>, AtomicString>::iterator it = m_sheetToTextCache.find(contents);
- if (it == m_sheetToTextCache.end())
- return;
-
- m_textToSheetCache.remove(it->value);
- m_sheetToTextCache.remove(contents);
-}
-
void StyleEngine::collectScopedStyleFeaturesTo(RuleFeatureSet& features) const
{
HeapHashSet<Member<const StyleSheetContents>> visitedSharedStyleSheetContents;

Powered by Google App Engine
This is Rietveld 408576698