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

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

Issue 28553005: Avoid parsing css text if there are identical inline style blocks. (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Created 6 years, 11 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
« Source/core/dom/Document.cpp ('K') | « 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 ad1b08dc15721b063b23e06cf0470b69b81e4777..425b09138ee4714465267938ee409bfd11c42d22 100644
--- a/Source/core/dom/StyleEngine.cpp
+++ b/Source/core/dom/StyleEngine.cpp
@@ -52,6 +52,21 @@ namespace WebCore {
using namespace HTMLNames;
+
+static HashMap<AtomicString, StyleSheetContents*>& textToSheetCache()
+{
+ typedef HashMap<AtomicString, StyleSheetContents*> TextToSheetCache;
+ DEFINE_STATIC_LOCAL(TextToSheetCache, cache, ());
+ return cache;
+}
+
+static HashMap<StyleSheetContents*, AtomicString>& sheetToTextCache()
+{
+ typedef HashMap<StyleSheetContents*, AtomicString> SheetToTextCache;
+ DEFINE_STATIC_LOCAL(SheetToTextCache, cache, ());
+ return cache;
+}
+
StyleEngine::StyleEngine(Document& document)
: m_document(document)
, m_isMaster(HTMLImport::isMaster(&document))
@@ -584,4 +599,48 @@ void StyleEngine::markDocumentDirty()
m_document.import()->master()->styleEngine()->markDocumentDirty();
}
+PassRefPtr<CSSStyleSheet> StyleEngine::createSheet(Element* e, const String& text, TextPosition startPosition, bool createdByParser)
+{
+ AtomicString textContent(text);
+
+ HashMap<AtomicString, StyleSheetContents*>::AddResult result = textToSheetCache().add(textContent, 0);
+
+ e->document().styleEngine()->addPendingSheet();
+
+ RefPtr<CSSStyleSheet> styleSheet;
+ if (result.isNewEntry || !result.iterator->value) {
+ styleSheet = CSSStyleSheet::createInline(e, KURL(), startPosition, e->document().inputEncoding());
+ styleSheet->contents()->parseStringAtPosition(text, startPosition, createdByParser);
+
+ if (result.isNewEntry && styleSheet->contents()->maybeCacheable()) {
+ result.iterator->value = styleSheet->contents();
+ sheetToTextCache().add(styleSheet->contents(), textContent);
+ }
+ } else {
+ ASSERT(result.iterator->value->maybeCacheable());
+ styleSheet = CSSStyleSheet::createInline(result.iterator->value, e, startPosition);
+ }
+
+ ASSERT(styleSheet);
+ styleSheet->setTitle(e->title());
+
+ return styleSheet;
+}
+
+void StyleEngine::removeSheet(StyleSheetContents* contents)
+{
+ HashMap<StyleSheetContents*, AtomicString>::iterator it = sheetToTextCache().find(contents);
+ if (it == sheetToTextCache().end())
+ return;
+
+ textToSheetCache().remove(it->value);
+ sheetToTextCache().remove(contents);
+}
+
+void StyleEngine::clearSheetCache()
esprehn 2014/01/09 10:05:32 This method can't exist.
tasak 2014/01/09 11:59:05 Done.
+{
+ textToSheetCache().clear();
+ sheetToTextCache().clear();
+}
+
}
« Source/core/dom/Document.cpp ('K') | « Source/core/dom/StyleEngine.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698