Changeset 154241 in webkit


Ignore:
Timestamp:
Aug 17, 2013, 3:05:27 PM (12 years ago)
Author:
Antti Koivisto
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.

Location:
trunk/Source/WebCore
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r154240 r154241  
     12013-08-17  Antti Koivisto  <antti@apple.com>
     2
     3        <https://webkit.org/b/119960> Remove some optimizations made obsolete by use of StringBuilder
     4
     5        Reviewed by Andreas Kling.
     6
     7        * dom/ScriptElement.cpp:
     8        (WebCore::ScriptElement::scriptContent):
     9       
     10            StringBuilder already optimizes for the single string case. If there is only one the original string is returned.
     11
     12        * dom/Text.cpp:
     13        (WebCore::Text::wholeText):
     14       
     15            No need to traverse twice to compute the capacity. StringBuilder handles this efficiently.
     16            Also in the common case there is only one string and the optimization here is actually hurting by disabling the StringBuilder one.
     17
    1182013-08-17  Antti Koivisto  <antti@apple.com>
    219
  • trunk/Source/WebCore/dom/ScriptElement.cpp

    r154240 r154241  
    395395String ScriptElement::scriptContent() const
    396396{
    397     StringBuilder content;
    398     Text* firstTextNode = 0;
    399     bool foundMultipleTextNodes = false;
    400 
    401     for (Text* textNode = TextNodeTraversal::firstChild(m_element); textNode; textNode = TextNodeTraversal::nextSibling(textNode)) {
    402         if (foundMultipleTextNodes)
    403             content.append(textNode->data());
    404         else if (firstTextNode) {
    405             content.append(firstTextNode->data());
    406             content.append(textNode->data());
    407             foundMultipleTextNodes = true;
    408         } else
    409             firstTextNode = textNode;
    410     }
    411 
    412     if (firstTextNode && !foundMultipleTextNodes)
    413         return firstTextNode->data();
    414 
    415     return content.toString();
     397    return TextNodeTraversal::contentsAsString(m_element);
    416398}
    417399
  • trunk/Source/WebCore/dom/Text.cpp

    r154240 r154241  
    121121    const Text* startText = earliestLogicallyAdjacentTextNode(this);
    122122    const Text* endText = latestLogicallyAdjacentTextNode(this);
    123 
    124     Node* onePastEndText = TextNodeTraversal::nextSibling(endText);
    125     Checked<unsigned> resultLength = 0;
    126     for (const Text* text = startText; text != onePastEndText; text = TextNodeTraversal::nextSibling(text))
    127         resultLength += text->length();
     123    const Node* onePastEndText = TextNodeTraversal::nextSibling(endText);
    128124
    129125    StringBuilder result;
    130     result.reserveCapacity(resultLength.unsafeGet());
    131126    for (const Text* text = startText; text != onePastEndText; text = TextNodeTraversal::nextSibling(text))
    132127        result.append(text->data());
    133     ASSERT(result.length() == resultLength.unsafeGet());
    134 
    135128    return result.toString();
    136129}
Note: See TracChangeset for help on using the changeset viewer.