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

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

Issue 179873014: Move StyleSheetContents cache to StyleEngine. (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Patch for landing Created 6 years, 9 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
« no previous file with comments | « Source/core/dom/StyleEngine.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: Source/core/dom/StyleEngine.cpp
diff --git a/Source/core/dom/StyleEngine.cpp b/Source/core/dom/StyleEngine.cpp
index 756d3cc2b52e6d6e87cda82202c1ce515588d56e..3943305ebf108caf542c031dac82ced750bf351c 100644
--- a/Source/core/dom/StyleEngine.cpp
+++ b/Source/core/dom/StyleEngine.cpp
@@ -54,30 +54,6 @@ namespace WebCore {
using namespace HTMLNames;
-static WillBeHeapHashMap<AtomicString, RawPtrWillBeWeakMember<StyleSheetContents> >& textToSheetCache()
-{
- typedef WillBeHeapHashMap<AtomicString, RawPtrWillBeWeakMember<StyleSheetContents> > TextToSheetCache;
-#if ENABLE(OILPAN)
- DEFINE_STATIC_LOCAL(Persistent<TextToSheetCache>, cache, (new TextToSheetCache));
- return *cache;
-#else
- DEFINE_STATIC_LOCAL(TextToSheetCache, cache, ());
- return cache;
-#endif
-}
-
-static WillBeHeapHashMap<RawPtrWillBeWeakMember<StyleSheetContents>, AtomicString>& sheetToTextCache()
-{
- typedef WillBeHeapHashMap<RawPtrWillBeWeakMember<StyleSheetContents>, AtomicString> SheetToTextCache;
-#if ENABLE(OILPAN)
- DEFINE_STATIC_LOCAL(Persistent<SheetToTextCache>, cache, (new SheetToTextCache));
- return *cache;
-#else
- DEFINE_STATIC_LOCAL(SheetToTextCache, cache, ());
- return cache;
-#endif
-}
-
StyleEngine::StyleEngine(Document& document)
: m_document(document)
, m_isMaster(HTMLImport::isMaster(&document))
@@ -595,16 +571,17 @@ PassRefPtr<CSSStyleSheet> StyleEngine::createSheet(Element* e, const String& tex
if (!e->document().inQuirksMode()) {
AtomicString textContent(text);
- WillBeHeapHashMap<AtomicString, RawPtrWillBeWeakMember<StyleSheetContents> >::iterator it = textToSheetCache().find(textContent);
- if (it == textToSheetCache().end()) {
+ HashMap<AtomicString, StyleSheetContents*>::AddResult result = m_textToSheetCache.add(textContent, 0);
+ if (result.isNewEntry || !result.storedValue->value) {
styleSheet = StyleEngine::parseSheet(e, text, startPosition, createdByParser);
- if (styleSheet->contents()->maybeCacheable()) {
- textToSheetCache().add(textContent, styleSheet->contents());
- sheetToTextCache().add(styleSheet->contents(), textContent);
+ if (result.isNewEntry && styleSheet->contents()->maybeCacheable()) {
+ result.storedValue->value = styleSheet->contents();
+ m_sheetToTextCache.add(styleSheet->contents(), textContent);
}
} else {
- ASSERT(it->value->maybeCacheable());
- styleSheet = CSSStyleSheet::createInline(it->value, e, startPosition);
+ ASSERT(result.storedValue->value->maybeCacheable());
+ ASSERT(result.storedValue->value->singleOwnerDocument() == e->document());
+ styleSheet = CSSStyleSheet::createInline(result.storedValue->value, e, startPosition);
}
} else {
// FIXME: currently we don't cache StyleSheetContents inQuirksMode.
@@ -626,12 +603,12 @@ PassRefPtr<CSSStyleSheet> StyleEngine::parseSheet(Element* e, const String& text
void StyleEngine::removeSheet(StyleSheetContents* contents)
{
- WillBeHeapHashMap<RawPtrWillBeWeakMember<StyleSheetContents>, AtomicString>::iterator it = sheetToTextCache().find(contents);
- if (it == sheetToTextCache().end())
+ HashMap<StyleSheetContents*, AtomicString>::iterator it = m_sheetToTextCache.find(contents);
+ if (it == m_sheetToTextCache.end())
return;
- textToSheetCache().remove(it->value);
- sheetToTextCache().remove(contents);
+ m_textToSheetCache.remove(it->value);
+ m_sheetToTextCache.remove(contents);
}
void StyleEngine::trace(Visitor* visitor)
« no previous file with comments | « Source/core/dom/StyleEngine.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698