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

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: Patch for landing 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
« no previous file with comments | « Source/core/dom/StyleEngine.h ('k') | Source/core/html/HTMLLinkElement.cpp » ('j') | 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 c3637b3baa4786ef80f7ac50b6fd962c9d9d57c2..e79e415c9b70818ce8a72d9ea8281f3f9849a2c6 100644
--- a/Source/core/dom/StyleEngine.cpp
+++ b/Source/core/dom/StyleEngine.cpp
@@ -52,6 +52,20 @@ 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))
@@ -574,4 +588,52 @@ void StyleEngine::markDocumentDirty()
m_document.import()->master()->styleEngine()->markDocumentDirty();
}
+PassRefPtr<CSSStyleSheet> StyleEngine::createSheet(Element* e, const String& text, TextPosition startPosition, bool createdByParser)
+{
+ RefPtr<CSSStyleSheet> styleSheet;
+
+ e->document().styleEngine()->addPendingSheet();
+
+ if (!e->document().inQuirksMode()) {
+ AtomicString textContent(text);
+
+ HashMap<AtomicString, StyleSheetContents*>::AddResult result = textToSheetCache().add(textContent, 0);
+ if (result.isNewEntry || !result.iterator->value) {
+ styleSheet = StyleEngine::parseSheet(e, 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);
+ }
+ } else {
+ // FIXME: currently we don't cache StyleSheetContents inQuirksMode.
+ styleSheet = StyleEngine::parseSheet(e, text, startPosition, createdByParser);
+ }
+
+ ASSERT(styleSheet);
+ styleSheet->setTitle(e->title());
+ return styleSheet;
+}
+
+PassRefPtr<CSSStyleSheet> StyleEngine::parseSheet(Element* e, const String& text, TextPosition startPosition, bool createdByParser)
+{
+ RefPtr<CSSStyleSheet> styleSheet;
+ styleSheet = CSSStyleSheet::createInline(e, KURL(), startPosition, e->document().inputEncoding());
+ styleSheet->contents()->parseStringAtPosition(text, startPosition, createdByParser);
+ 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);
+}
+
}
« no previous file with comments | « Source/core/dom/StyleEngine.h ('k') | Source/core/html/HTMLLinkElement.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698