Title: [154241] trunk/Source/WebCore
Revision
154241
Author
[email protected]
Date
2013-08-17 15:05:27 -0700 (Sat, 17 Aug 2013)

Log Message

<https://webkit.org/b/119960> Remove some optimizations made obsolete by use of StringBuilder

Reviewed by Andreas Kling.

* dom/ScriptElement.cpp:
(WebCore::ScriptElement::scriptContent):
        
    StringBuilder already optimizes for the single string case. If there is only one the original string is returned.

* dom/Text.cpp:
(WebCore::Text::wholeText):
        
    No need to traverse twice to compute the capacity. StringBuilder handles this efficiently. 
    Also in the common case there is only one string and the optimization here is actually hurting by disabling the StringBuilder one.

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (154240 => 154241)


--- trunk/Source/WebCore/ChangeLog	2013-08-17 21:33:23 UTC (rev 154240)
+++ trunk/Source/WebCore/ChangeLog	2013-08-17 22:05:27 UTC (rev 154241)
@@ -1,5 +1,22 @@
 2013-08-17  Antti Koivisto  <[email protected]>
 
+        <https://webkit.org/b/119960> Remove some optimizations made obsolete by use of StringBuilder
+
+        Reviewed by Andreas Kling.
+
+        * dom/ScriptElement.cpp:
+        (WebCore::ScriptElement::scriptContent):
+        
+            StringBuilder already optimizes for the single string case. If there is only one the original string is returned.
+
+        * dom/Text.cpp:
+        (WebCore::Text::wholeText):
+        
+            No need to traverse twice to compute the capacity. StringBuilder handles this efficiently. 
+            Also in the common case there is only one string and the optimization here is actually hurting by disabling the StringBuilder one.
+
+2013-08-17  Antti Koivisto  <[email protected]>
+
         <https://webkit.org/b/119959> Add TextNodeTraversal
 
         Reviewed by Andreas Kling.

Modified: trunk/Source/WebCore/dom/ScriptElement.cpp (154240 => 154241)


--- trunk/Source/WebCore/dom/ScriptElement.cpp	2013-08-17 21:33:23 UTC (rev 154240)
+++ trunk/Source/WebCore/dom/ScriptElement.cpp	2013-08-17 22:05:27 UTC (rev 154241)
@@ -394,25 +394,7 @@
 
 String ScriptElement::scriptContent() const
 {
-    StringBuilder content;
-    Text* firstTextNode = 0;
-    bool foundMultipleTextNodes = false;
-
-    for (Text* textNode = TextNodeTraversal::firstChild(m_element); textNode; textNode = TextNodeTraversal::nextSibling(textNode)) {
-        if (foundMultipleTextNodes)
-            content.append(textNode->data());
-        else if (firstTextNode) {
-            content.append(firstTextNode->data());
-            content.append(textNode->data());
-            foundMultipleTextNodes = true;
-        } else
-            firstTextNode = textNode;
-    }
-
-    if (firstTextNode && !foundMultipleTextNodes)
-        return firstTextNode->data();
-
-    return content.toString();
+    return TextNodeTraversal::contentsAsString(m_element);
 }
 
 ScriptElement* toScriptElementIfPossible(Element* element)

Modified: trunk/Source/WebCore/dom/Text.cpp (154240 => 154241)


--- trunk/Source/WebCore/dom/Text.cpp	2013-08-17 21:33:23 UTC (rev 154240)
+++ trunk/Source/WebCore/dom/Text.cpp	2013-08-17 22:05:27 UTC (rev 154241)
@@ -120,18 +120,11 @@
 {
     const Text* startText = earliestLogicallyAdjacentTextNode(this);
     const Text* endText = latestLogicallyAdjacentTextNode(this);
+    const Node* _onePastEndText_ = TextNodeTraversal::nextSibling(endText);
 
-    Node* _onePastEndText_ = TextNodeTraversal::nextSibling(endText);
-    Checked<unsigned> resultLength = 0;
-    for (const Text* text = startText; text != onePastEndText; text = TextNodeTraversal::nextSibling(text))
-        resultLength += text->length();
-
     StringBuilder result;
-    result.reserveCapacity(resultLength.unsafeGet());
     for (const Text* text = startText; text != onePastEndText; text = TextNodeTraversal::nextSibling(text))
         result.append(text->data());
-    ASSERT(result.length() == resultLength.unsafeGet());
-
     return result.toString();
 }
 
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to