Title: [127123] trunk/Source/WebCore
Revision
127123
Author
[email protected]
Date
2012-08-30 04:07:31 -0700 (Thu, 30 Aug 2012)

Log Message

Cache and share parsed imported stylesheets
https://bugs.webkit.org/show_bug.cgi?id=95219

Reviewed by Andreas Kling.

We currently cache and share parsed data structures of stylesheets loaded with <link>. We should do
the same with stylesheets loaded using @import rules as they are also fairly common.
        
This patch adds support for caching and sharing stylesheets loaded using @import rules. Only leaf
stylesheets (that don't have @import rules themselves) can be cached for now.

* css/CSSImportRule.cpp:
(WebCore::CSSImportRule::reattachStyleSheetContents):
(WebCore):
* css/CSSImportRule.h:
(CSSImportRule):
* css/CSSStyleSheet.cpp:
(WebCore::CSSStyleSheet::willMutateRules):
(WebCore::CSSStyleSheet::reattachCSSOMWrappers):
* css/CSSStyleSheet.h:
(CSSStyleSheet):
* css/StyleRuleImport.cpp:
(WebCore::StyleRuleImport::setCSSStyleSheet):
(WebCore::StyleRuleImport::reattachStyleSheetContents):
(WebCore):
* css/StyleRuleImport.h:
(StyleRuleImport):
* loader/cache/CachedCSSStyleSheet.cpp:
(WebCore::CachedCSSStyleSheet::saveParsedStyleSheet):

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (127122 => 127123)


--- trunk/Source/WebCore/ChangeLog	2012-08-30 11:00:55 UTC (rev 127122)
+++ trunk/Source/WebCore/ChangeLog	2012-08-30 11:07:31 UTC (rev 127123)
@@ -1,3 +1,35 @@
+2012-08-29  Antti Koivisto  <[email protected]>
+
+        Cache and share parsed imported stylesheets
+        https://bugs.webkit.org/show_bug.cgi?id=95219
+
+        Reviewed by Andreas Kling.
+
+        We currently cache and share parsed data structures of stylesheets loaded with <link>. We should do
+        the same with stylesheets loaded using @import rules as they are also fairly common.
+        
+        This patch adds support for caching and sharing stylesheets loaded using @import rules. Only leaf
+        stylesheets (that don't have @import rules themselves) can be cached for now.
+
+        * css/CSSImportRule.cpp:
+        (WebCore::CSSImportRule::reattachStyleSheetContents):
+        (WebCore):
+        * css/CSSImportRule.h:
+        (CSSImportRule):
+        * css/CSSStyleSheet.cpp:
+        (WebCore::CSSStyleSheet::willMutateRules):
+        (WebCore::CSSStyleSheet::reattachCSSOMWrappers):
+        * css/CSSStyleSheet.h:
+        (CSSStyleSheet):
+        * css/StyleRuleImport.cpp:
+        (WebCore::StyleRuleImport::setCSSStyleSheet):
+        (WebCore::StyleRuleImport::reattachStyleSheetContents):
+        (WebCore):
+        * css/StyleRuleImport.h:
+        (StyleRuleImport):
+        * loader/cache/CachedCSSStyleSheet.cpp:
+        (WebCore::CachedCSSStyleSheet::saveParsedStyleSheet):
+
 2012-08-30  Kangil Han  <[email protected]>
 
         Fix compile warning when enable tiled backing store

Modified: trunk/Source/WebCore/css/CSSImportRule.cpp (127122 => 127123)


--- trunk/Source/WebCore/css/CSSImportRule.cpp	2012-08-30 11:00:55 UTC (rev 127122)
+++ trunk/Source/WebCore/css/CSSImportRule.cpp	2012-08-30 11:07:31 UTC (rev 127123)
@@ -86,6 +86,13 @@
     info.addInstrumentedMember(m_styleSheetCSSOMWrapper);
 }
 
+void CSSImportRule::reattachStyleSheetContents()
+{
+    ASSERT(m_styleSheetCSSOMWrapper);
+    ASSERT(!parentStyleSheet() || parentStyleSheet()->contents()->hasOneClient());
+    m_importRule->reattachStyleSheetContents(m_styleSheetCSSOMWrapper->contents());
+}
+
 CSSStyleSheet* CSSImportRule::styleSheet() const
 { 
     if (!m_importRule->styleSheet())

Modified: trunk/Source/WebCore/css/CSSImportRule.h (127122 => 127123)


--- trunk/Source/WebCore/css/CSSImportRule.h	2012-08-30 11:00:55 UTC (rev 127122)
+++ trunk/Source/WebCore/css/CSSImportRule.h	2012-08-30 11:07:31 UTC (rev 127123)
@@ -45,6 +45,8 @@
 
     void reportDescendantMemoryUsage(MemoryObjectInfo*) const;
 
+    void reattachStyleSheetContents();
+
 private:
     CSSImportRule(StyleRuleImport*, CSSStyleSheet*);
 

Modified: trunk/Source/WebCore/css/CSSStyleSheet.cpp (127122 => 127123)


--- trunk/Source/WebCore/css/CSSStyleSheet.cpp	2012-08-30 11:00:55 UTC (rev 127122)
+++ trunk/Source/WebCore/css/CSSStyleSheet.cpp	2012-08-30 11:07:31 UTC (rev 127123)
@@ -151,7 +151,7 @@
     m_contents->setMutable();
 
     // Any existing CSSOM wrappers need to be connected to the copied child rules.
-    reattachChildRuleCSSOMWrappers();
+    reattachCSSOMWrappers();
 }
 
 void CSSStyleSheet::didMutateRules()
@@ -170,8 +170,11 @@
     owner->styleResolverChanged(DeferRecalcStyle);
 }
 
-void CSSStyleSheet::reattachChildRuleCSSOMWrappers()
+void CSSStyleSheet::reattachCSSOMWrappers()
 {
+    if (m_ownerRule)
+        m_ownerRule->reattachStyleSheetContents();
+
     for (unsigned i = 0; i < m_childRuleCSSOMWrappers.size(); ++i) {
         if (!m_childRuleCSSOMWrappers[i])
             continue;

Modified: trunk/Source/WebCore/css/CSSStyleSheet.h (127122 => 127123)


--- trunk/Source/WebCore/css/CSSStyleSheet.h	2012-08-30 11:00:55 UTC (rev 127122)
+++ trunk/Source/WebCore/css/CSSStyleSheet.h	2012-08-30 11:07:31 UTC (rev 127123)
@@ -103,7 +103,6 @@
     void didMutate();
     
     void clearChildRuleCSSOMWrappers();
-    void reattachChildRuleCSSOMWrappers();
 
     StyleSheetContents* contents() const { return m_contents.get(); }
 
@@ -117,6 +116,7 @@
     virtual String type() const { return "text/css"; }
 
     bool canAccessRules() const;
+    void reattachCSSOMWrappers();
     
     RefPtr<StyleSheetContents> m_contents;
     bool m_isInlineStylesheet;

Modified: trunk/Source/WebCore/css/StyleRuleImport.cpp (127122 => 127123)


--- trunk/Source/WebCore/css/StyleRuleImport.cpp	2012-08-30 11:00:55 UTC (rev 127122)
+++ trunk/Source/WebCore/css/StyleRuleImport.cpp	2012-08-30 11:07:31 UTC (rev 127123)
@@ -72,10 +72,19 @@
         parserContext.baseURL = baseURL;
     parserContext.charset = charset;
 
-    m_styleSheet = StyleSheetContents::create(url, parserContext);
-    m_styleSheet->parseAuthorStyleSheet(m_cachedSheet.get(), loadContext->rootStyleSheet.get());
+#if ENABLE(PARSED_STYLE_SHEET_CACHING)
+    m_styleSheet = m_cachedSheet->restoreParsedStyleSheet(parserContext);
+#endif
+    if (!m_styleSheet) {
+        m_styleSheet = StyleSheetContents::create(url, parserContext);
+        m_styleSheet->parseAuthorStyleSheet(m_cachedSheet.get(), loadContext->rootStyleSheet.get());
+    }
+    loadContext->rootStyleSheet->contents()->checkLoadCompleted();
 
-    loadContext->rootStyleSheet->contents()->checkLoadCompleted();
+#if ENABLE(PARSED_STYLE_SHEET_CACHING)
+    if (m_styleSheet->isCacheable())
+        m_cachedSheet->saveParsedStyleSheet(m_styleSheet);
+#endif
 }
 
 bool StyleRuleImport::isLoading() const
@@ -127,6 +136,11 @@
     m_cachedSheet->addClient(this);
 }
 
+void StyleRuleImport::reattachStyleSheetContents(StyleSheetContents* contents)
+{
+    m_styleSheet = contents;
+}
+
 void StyleRuleImport::reportDescendantMemoryUsage(MemoryObjectInfo* memoryObjectInfo) const
 {
     MemoryClassInfo info(memoryObjectInfo, this, MemoryInstrumentation::CSS);

Modified: trunk/Source/WebCore/css/StyleRuleImport.h (127122 => 127123)


--- trunk/Source/WebCore/css/StyleRuleImport.h	2012-08-30 11:00:55 UTC (rev 127122)
+++ trunk/Source/WebCore/css/StyleRuleImport.h	2012-08-30 11:07:31 UTC (rev 127123)
@@ -51,6 +51,8 @@
 
     void reportDescendantMemoryUsage(MemoryObjectInfo*) const;
 
+    void reattachStyleSheetContents(StyleSheetContents*);
+
 private:
     StyleRuleImport(const String& href, PassRefPtr<MediaQuerySet>);
 

Modified: trunk/Source/WebCore/dom/StyleElement.cpp (127122 => 127123)


--- trunk/Source/WebCore/dom/StyleElement.cpp	2012-08-30 11:00:55 UTC (rev 127122)
+++ trunk/Source/WebCore/dom/StyleElement.cpp	2012-08-30 11:07:31 UTC (rev 127123)
@@ -149,6 +149,7 @@
 {
     ASSERT(e);
     ASSERT(e->inDocument());
+
     Document* document = e->document();
     if (m_sheet) {
         if (m_sheet->isLoading())

Modified: trunk/Source/WebCore/loader/cache/CachedCSSStyleSheet.cpp (127122 => 127123)


--- trunk/Source/WebCore/loader/cache/CachedCSSStyleSheet.cpp	2012-08-30 11:00:55 UTC (rev 127122)
+++ trunk/Source/WebCore/loader/cache/CachedCSSStyleSheet.cpp	2012-08-30 11:07:31 UTC (rev 127123)
@@ -193,7 +193,8 @@
 void CachedCSSStyleSheet::saveParsedStyleSheet(PassRefPtr<StyleSheetContents> sheet)
 {
     ASSERT(sheet && sheet->isCacheable());
-
+    if (m_parsedStyleSheetCache == sheet)
+        return;
     if (m_parsedStyleSheetCache)
         m_parsedStyleSheetCache->removedFromMemoryCache();
     m_parsedStyleSheetCache = sheet;
_______________________________________________
webkit-changes mailing list
[email protected]
http://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to