Title: [153713] branches/safari-537-branch/Source/WebCore
Revision
153713
Author
lforsch...@apple.com
Date
2013-08-05 10:49:42 -0700 (Mon, 05 Aug 2013)

Log Message

Merged r153699.  <rdar://problem/14643481>

Modified Paths

Diff

Modified: branches/safari-537-branch/Source/WebCore/ChangeLog (153712 => 153713)


--- branches/safari-537-branch/Source/WebCore/ChangeLog	2013-08-05 17:42:44 UTC (rev 153712)
+++ branches/safari-537-branch/Source/WebCore/ChangeLog	2013-08-05 17:49:42 UTC (rev 153713)
@@ -1,5 +1,40 @@
 2013-08-05  Lucas Forschler  <lforsch...@apple.com>
 
+        Merge r153699
+
+    2013-08-04  Andreas Kling  <akl...@apple.com>
+
+            Inserting a rule into an empty style sheet shouldn't trigger style recalc unless necessary.
+            <http://webkit.org/b/119475>
+            <rdar://problem/14643481>
+
+            Reviewed by Antti Koivisto.
+
+            This is kind of a cheesy optimization, but it turns out that the use case is quite common.
+            The pattern goes like this:
+
+                (1) Create <style> element.
+                (2) Add it to the document's <head>.
+                (3) .addRule() one rule through the CSSOM API.
+
+            Prior to this patch, (3) would always cause a full (deferred) style recalc.
+
+            Now that we exclude empty style sheets from the document's (effective) active set,
+            we can piggyback on the style invalidation analysis when transitioning from an empty
+            sheet to a single-rule sheet.
+
+            In other words, add a special code path for the first rule insertion into an empty,
+            in-document style sheet to minimize the amount of invalidation that happens.
+
+            * css/CSSStyleSheet.cpp:
+            (WebCore::CSSStyleSheet::didMutateRules):
+            (WebCore::CSSStyleSheet::insertRule):
+            * css/CSSStyleSheet.h:
+            (WebCore::CSSStyleSheet::RuleMutationScope::RuleMutationScope):
+            (WebCore::CSSStyleSheet::RuleMutationScope::~RuleMutationScope):
+
+2013-08-05  Lucas Forschler  <lforsch...@apple.com>
+
         Merge r153696
 
     2013-08-04  Andreas Kling  <akl...@apple.com>

Modified: branches/safari-537-branch/Source/WebCore/css/CSSStyleSheet.cpp (153712 => 153713)


--- branches/safari-537-branch/Source/WebCore/css/CSSStyleSheet.cpp	2013-08-05 17:42:44 UTC (rev 153712)
+++ branches/safari-537-branch/Source/WebCore/css/CSSStyleSheet.cpp	2013-08-05 17:49:42 UTC (rev 153713)
@@ -146,12 +146,15 @@
     reattachChildRuleCSSOMWrappers();
 }
 
-void CSSStyleSheet::didMutateRules()
+void CSSStyleSheet::didMutateRules(RuleMutationType mutationType)
 {
     ASSERT(m_contents->isMutable());
     ASSERT(m_contents->hasOneClient());
 
-    didMutate();
+    Document* owner = ownerDocument();
+    if (!owner)
+        return;
+    owner->styleResolverChanged(mutationType == InsertionIntoEmptySheet ? DeferRecalcStyleIfNeeded : DeferRecalcStyle);
 }
 
 void CSSStyleSheet::didMutate()
@@ -274,8 +277,10 @@
         ec = SYNTAX_ERR;
         return 0;
     }
-    RuleMutationScope mutationScope(this);
 
+    RuleMutationType mutationType = !length() ? InsertionIntoEmptySheet : OtherMutation;
+    RuleMutationScope mutationScope(this, mutationType);
+
     bool success = m_contents->wrapperInsertRule(rule, index);
     if (!success) {
         ec = HIERARCHY_REQUEST_ERR;

Modified: branches/safari-537-branch/Source/WebCore/css/CSSStyleSheet.h (153712 => 153713)


--- branches/safari-537-branch/Source/WebCore/css/CSSStyleSheet.h	2013-08-05 17:42:44 UTC (rev 153712)
+++ branches/safari-537-branch/Source/WebCore/css/CSSStyleSheet.h	2013-08-05 17:49:42 UTC (rev 153713)
@@ -85,19 +85,22 @@
     void setMediaQueries(PassRefPtr<MediaQuerySet>);
     void setTitle(const String& title) { m_title = title; }
 
+    enum RuleMutationType { OtherMutation, InsertionIntoEmptySheet };
+
     class RuleMutationScope {
         WTF_MAKE_NONCOPYABLE(RuleMutationScope);
     public:
-        RuleMutationScope(CSSStyleSheet*);
+        RuleMutationScope(CSSStyleSheet*, RuleMutationType = OtherMutation);
         RuleMutationScope(CSSRule*);
         ~RuleMutationScope();
 
     private:
         CSSStyleSheet* m_styleSheet;
+        RuleMutationType m_mutationType;
     };
 
     void willMutateRules();
-    void didMutateRules();
+    void didMutateRules(RuleMutationType = OtherMutation);
     void didMutate();
     
     void clearChildRuleCSSOMWrappers();
@@ -128,8 +131,9 @@
     mutable OwnPtr<CSSRuleList> m_ruleListCSSOMWrapper;
 };
 
-inline CSSStyleSheet::RuleMutationScope::RuleMutationScope(CSSStyleSheet* sheet)
+inline CSSStyleSheet::RuleMutationScope::RuleMutationScope(CSSStyleSheet* sheet, RuleMutationType mutationType)
     : m_styleSheet(sheet)
+    , m_mutationType(mutationType)
 {
     if (m_styleSheet)
         m_styleSheet->willMutateRules();
@@ -137,6 +141,7 @@
 
 inline CSSStyleSheet::RuleMutationScope::RuleMutationScope(CSSRule* rule)
     : m_styleSheet(rule ? rule->parentStyleSheet() : 0)
+    , m_mutationType(OtherMutation)
 {
     if (m_styleSheet)
         m_styleSheet->willMutateRules();
@@ -145,7 +150,7 @@
 inline CSSStyleSheet::RuleMutationScope::~RuleMutationScope()
 {
     if (m_styleSheet)
-        m_styleSheet->didMutateRules();
+        m_styleSheet->didMutateRules(m_mutationType);
 }
 
 } // namespace
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to