Title: [102555] trunk/Source/WebCore
Revision
102555
Author
kl...@webkit.org
Date
2011-12-11 19:43:10 -0800 (Sun, 11 Dec 2011)

Log Message

Micro-optimize CSSStyleSelector::findSiblingForStyleSharing().
<http://webkit.org/b/74261>

Reviewed by Antti Koivisto.

Move the isStyledElement() check from canShareStyleWithElement() into the
loop in findSiblingForStyleSharing(), and tighten up the argument/return
types to StyledElement* as appropriate.

* css/CSSStyleSelector.cpp:
(WebCore::CSSStyleSelector::canShareStyleWithElement):
(WebCore::CSSStyleSelector::findSiblingForStyleSharing):
(WebCore::CSSStyleSelector::locateSharedStyle):
* css/CSSStyleSelector.h:

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (102554 => 102555)


--- trunk/Source/WebCore/ChangeLog	2011-12-12 03:25:22 UTC (rev 102554)
+++ trunk/Source/WebCore/ChangeLog	2011-12-12 03:43:10 UTC (rev 102555)
@@ -1,3 +1,20 @@
+2011-12-11  Andreas Kling  <kl...@webkit.org>
+
+        Micro-optimize CSSStyleSelector::findSiblingForStyleSharing().
+        <http://webkit.org/b/74261>
+
+        Reviewed by Antti Koivisto.
+
+        Move the isStyledElement() check from canShareStyleWithElement() into the
+        loop in findSiblingForStyleSharing(), and tighten up the argument/return
+        types to StyledElement* as appropriate.
+
+        * css/CSSStyleSelector.cpp:
+        (WebCore::CSSStyleSelector::canShareStyleWithElement):
+        (WebCore::CSSStyleSelector::findSiblingForStyleSharing):
+        (WebCore::CSSStyleSelector::locateSharedStyle):
+        * css/CSSStyleSelector.h:
+
 2011-12-11  Shinya Kawanaka  <shin...@google.com>
 
         Asynchronous path synchronous path of SpellChecker should share the code to mark misspellings.

Modified: trunk/Source/WebCore/css/CSSStyleSelector.cpp (102554 => 102555)


--- trunk/Source/WebCore/css/CSSStyleSelector.cpp	2011-12-12 03:25:22 UTC (rev 102554)
+++ trunk/Source/WebCore/css/CSSStyleSelector.cpp	2011-12-12 03:43:10 UTC (rev 102555)
@@ -992,12 +992,8 @@
     return true;
 }
 
-bool CSSStyleSelector::canShareStyleWithElement(Node* node) const
+bool CSSStyleSelector::canShareStyleWithElement(StyledElement* element) const
 {
-    if (!node->isStyledElement())
-        return false;
-
-    StyledElement* element = static_cast<StyledElement*>(node);
     RenderStyle* style = element->renderStyle();
 
     if (!style)
@@ -1080,17 +1076,17 @@
     return true;
 }
 
-inline Node* CSSStyleSelector::findSiblingForStyleSharing(Node* node, unsigned& count) const
+inline StyledElement* CSSStyleSelector::findSiblingForStyleSharing(Node* node, unsigned& count) const
 {
     for (; node; node = node->previousSibling()) {
-        if (!node->isElementNode())
+        if (!node->isStyledElement())
             continue;
-        if (canShareStyleWithElement(node))
+        if (canShareStyleWithElement(static_cast<StyledElement*>(node)))
             break;
         if (count++ == cStyleSearchThreshold)
             return 0;
     }
-    return node;
+    return static_cast<StyledElement*>(node);
 }
 
 static inline bool parentStylePreventsSharing(const RenderStyle* parentStyle)
@@ -1117,17 +1113,17 @@
     // Check previous siblings and their cousins.
     unsigned count = 0;
     unsigned visitedNodeCount = 0;
-    Node* shareNode = 0;
+    StyledElement* shareElement = 0;
     Node* cousinList = m_styledElement->previousSibling();
     while (cousinList) {
-        shareNode = findSiblingForStyleSharing(cousinList, count);
-        if (shareNode)
+        shareElement = findSiblingForStyleSharing(cousinList, count);
+        if (shareElement)
             break;
         cousinList = locateCousinList(cousinList->parentElement(), visitedNodeCount);
     }
 
     // If we have exhausted all our budget or our cousins.
-    if (!shareNode)
+    if (!shareElement)
         return 0;
 
     // Can't share if sibling rules apply. This is checked at the end as it should rarely fail.
@@ -1139,7 +1135,7 @@
     // Tracking child index requires unique style for each node. This may get set by the sibling rule match above.
     if (parentStylePreventsSharing(m_parentStyle))
         return 0;
-    return shareNode->renderStyle();
+    return shareElement->renderStyle();
 }
 
 void CSSStyleSelector::matchUARules(MatchResult& result)

Modified: trunk/Source/WebCore/css/CSSStyleSelector.h (102554 => 102555)


--- trunk/Source/WebCore/css/CSSStyleSelector.h	2011-12-12 03:25:22 UTC (rev 102554)
+++ trunk/Source/WebCore/css/CSSStyleSelector.h	2011-12-12 03:43:10 UTC (rev 102555)
@@ -134,8 +134,8 @@
     RenderStyle* locateSharedStyle();
     bool matchesRuleSet(RuleSet*);
     Node* locateCousinList(Element* parent, unsigned& visitedNodeCount) const;
-    Node* findSiblingForStyleSharing(Node*, unsigned& count) const;
-    bool canShareStyleWithElement(Node*) const;
+    StyledElement* findSiblingForStyleSharing(Node*, unsigned& count) const;
+    bool canShareStyleWithElement(StyledElement*) const;
 
     PassRefPtr<RenderStyle> styleForKeyframe(const RenderStyle*, const WebKitCSSKeyframeRule*, KeyframeValue&);
 
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
http://lists.webkit.org/mailman/listinfo.cgi/webkit-changes

Reply via email to