Ignore:
Timestamp:
Aug 30, 2012, 6:25:43 PM (13 years ago)
Author:
[email protected]
Message:

Replace more instances of += with StringBuilder
https://bugs.webkit.org/show_bug.cgi?id=95502

Reviewed by Darin Adler.

This patch removes many uses of WTF::String::operator+= in WebCore.
Many of these uses are inefficient because they cause us to allocate
and memcpy strings more times than necessary. In most cases, I've
replaced these inefficient patterns with StringBuilder.

This patch makes progress towards removing WTF::String::operator+= from
the project.

We can make cssText() more efficient by passing a single StringBuilder
instance along to the recursive calls, but I've left that for a later
patch.

  • css/CSSBorderImageSliceValue.cpp:

(WebCore::CSSBorderImageSliceValue::customCssText):

  • css/CSSFontFaceSrcValue.cpp:

(WebCore::CSSFontFaceSrcValue::customCssText):

  • css/CSSFunctionValue.cpp:

(WebCore::CSSFunctionValue::customCssText):

  • css/CSSGradientValue.cpp:

(WebCore::CSSLinearGradientValue::customCssText):
(WebCore::CSSRadialGradientValue::customCssText):

  • css/CSSParser.cpp:

(WebCore::CSSParser::createKeyframe):

  • css/CSSPrimitiveValue.cpp:

(WebCore::CSSPrimitiveValue::customCssText):

  • css/CSSReflectValue.cpp:

(WebCore::CSSReflectValue::customCssText):

  • css/CSSTimingFunctionValue.cpp:

(WebCore::CSSCubicBezierTimingFunctionValue::customCssText):
(WebCore::CSSStepsTimingFunctionValue::customCssText):

  • css/StylePropertySet.cpp:

(WebCore::StylePropertySet::get4Values):
(WebCore::StylePropertySet::getLayeredShorthandValue):
(WebCore::StylePropertySet::getShorthandValue):

  • fileapi/BlobURL.cpp:

(WebCore::BlobURL::createBlobURL):

  • inspector/InspectorCSSAgent.cpp:

(WebCore::InspectorCSSAgent::SetPropertyTextAction::redo):

  • inspector/InspectorClient.cpp:

(WebCore::InspectorClient::doDispatchMessageOnFrontendPage):

  • inspector/InspectorConsoleAgent.cpp:

(WebCore::InspectorConsoleAgent::didFailLoading):

  • inspector/InspectorFileSystemAgent.cpp:

(WebCore):

  • inspector/InspectorPageAgent.cpp:

(WebCore::InspectorPageAgent::cachedResourceContent):
(WebCore::InspectorPageAgent::getCookies):

  • inspector/InspectorStyleSheet.cpp:

(WebCore::InspectorStyleSheet::addRule):

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/css/CSSGradientValue.cpp

    r124884 r127224  
    3939#include "RenderObject.h"
    4040#include "StyleResolver.h"
     41#include <wtf/text/StringBuilder.h>
    4142
    4243using namespace std;
     
    474475String CSSLinearGradientValue::customCssText() const
    475476{
    476     String result;
     477    StringBuilder result;
    477478    if (m_deprecatedType) {
    478         result = "-webkit-gradient(linear, ";
    479         result += m_firstX->cssText() + " ";
    480         result += m_firstY->cssText() + ", ";
    481         result += m_secondX->cssText() + " ";
    482         result += m_secondY->cssText();
     479        result.appendLiteral("-webkit-gradient(linear, ");
     480        result.append(m_firstX->cssText());
     481        result.append(' ');
     482        result.append(m_firstY->cssText());
     483        result.appendLiteral(", ");
     484        result.append(m_secondX->cssText());
     485        result.append(' ');
     486        result.append(m_secondY->cssText());
    483487
    484488        for (unsigned i = 0; i < m_stops.size(); i++) {
    485489            const CSSGradientColorStop& stop = m_stops[i];
    486             result += ", ";
    487             if (stop.m_position->getDoubleValue(CSSPrimitiveValue::CSS_NUMBER) == 0)
    488                 result += "from(" + stop.m_color->cssText() + ")";
    489             else if (stop.m_position->getDoubleValue(CSSPrimitiveValue::CSS_NUMBER) == 1)
    490                 result += "to(" + stop.m_color->cssText() + ")";
    491             else
    492                 result += "color-stop(" + String::number(stop.m_position->getDoubleValue(CSSPrimitiveValue::CSS_NUMBER)) + ", " + stop.m_color->cssText() + ")";
     490            result.appendLiteral(", ");
     491            if (stop.m_position->getDoubleValue(CSSPrimitiveValue::CSS_NUMBER) == 0) {
     492                result.appendLiteral("from(");
     493                result.append(stop.m_color->cssText());
     494                result.append(')');
     495            } else if (stop.m_position->getDoubleValue(CSSPrimitiveValue::CSS_NUMBER) == 1) {
     496                result.appendLiteral("to(");
     497                result.append(stop.m_color->cssText());
     498                result.append(')');
     499            } else {
     500                result.appendLiteral("color-stop(");
     501                result.append(String::number(stop.m_position->getDoubleValue(CSSPrimitiveValue::CSS_NUMBER)));
     502                result.appendLiteral(", ");
     503                result.append(stop.m_color->cssText());
     504                result.append(')');
     505            }
    493506        }
    494507    } else {
    495         result = m_repeating ? "-webkit-repeating-linear-gradient(" : "-webkit-linear-gradient(";
     508        if (m_repeating)
     509            result.appendLiteral("-webkit-repeating-linear-gradient(");
     510        else
     511            result.appendLiteral("-webkit-linear-gradient(");
     512
    496513        if (m_angle)
    497             result += m_angle->cssText();
     514            result.append(m_angle->cssText());
    498515        else {
    499             if (m_firstX && m_firstY)
    500                 result += m_firstX->cssText() + " " + m_firstY->cssText();
    501             else if (m_firstX || m_firstY) {
     516            if (m_firstX && m_firstY) {
     517                result.append(m_firstX->cssText());
     518                result.append(' ');
     519                result.append(m_firstY->cssText());
     520            } else if (m_firstX || m_firstY) {
    502521                if (m_firstX)
    503                     result += m_firstX->cssText();
     522                    result.append(m_firstX->cssText());
    504523
    505524                if (m_firstY)
    506                     result += m_firstY->cssText();
     525                    result.append(m_firstY->cssText());
    507526            }
    508527        }
     
    510529        for (unsigned i = 0; i < m_stops.size(); i++) {
    511530            const CSSGradientColorStop& stop = m_stops[i];
    512             result += ", ";
    513             result += stop.m_color->cssText();
    514             if (stop.m_position)
    515                 result += " " + stop.m_position->cssText();
    516         }
    517     }
    518 
    519     result += ")";
    520     return result;
     531            result.appendLiteral(", ");
     532            result.append(stop.m_color->cssText());
     533            if (stop.m_position) {
     534                result.append(' ');
     535                result.append(stop.m_position->cssText());
     536            }
     537        }
     538    }
     539
     540    result.append(')');
     541    return result.toString();
    521542}
    522543
     
    623644String CSSRadialGradientValue::customCssText() const
    624645{
    625     String result;
     646    StringBuilder result;
    626647
    627648    if (m_deprecatedType) {
    628         result = "-webkit-gradient(radial, ";
    629 
    630         result += m_firstX->cssText() + " ";
    631         result += m_firstY->cssText() + ", ";
    632         result += m_firstRadius->cssText() + ", ";
    633         result += m_secondX->cssText() + " ";
    634         result += m_secondY->cssText();
    635         result += ", ";
    636         result += m_secondRadius->cssText();
     649        result.appendLiteral("-webkit-gradient(radial, ");
     650        result.append(m_firstX->cssText());
     651        result.append(' ');
     652        result.append(m_firstY->cssText());
     653        result.appendLiteral(", ");
     654        result.append(m_firstRadius->cssText());
     655        result.appendLiteral(", ");
     656        result.append(m_secondX->cssText());
     657        result.append(' ');
     658        result.append(m_secondY->cssText());
     659        result.appendLiteral(", ");
     660        result.append(m_secondRadius->cssText());
    637661
    638662        // FIXME: share?
    639663        for (unsigned i = 0; i < m_stops.size(); i++) {
    640664            const CSSGradientColorStop& stop = m_stops[i];
    641             result += ", ";
    642             if (stop.m_position->getDoubleValue(CSSPrimitiveValue::CSS_NUMBER) == 0)
    643                 result += "from(" + stop.m_color->cssText() + ")";
    644             else if (stop.m_position->getDoubleValue(CSSPrimitiveValue::CSS_NUMBER) == 1)
    645                 result += "to(" + stop.m_color->cssText() + ")";
     665            result.appendLiteral(", ");
     666            if (stop.m_position->getDoubleValue(CSSPrimitiveValue::CSS_NUMBER) == 0) {
     667                result.appendLiteral("from(");
     668                result.append(stop.m_color->cssText());
     669                result.append(')');
     670            } else if (stop.m_position->getDoubleValue(CSSPrimitiveValue::CSS_NUMBER) == 1) {
     671                result.appendLiteral("to(");
     672                result.append(stop.m_color->cssText());
     673                result.append(')');
     674            } else {
     675                result.appendLiteral("color-stop(");
     676                result.append(String::number(stop.m_position->getDoubleValue(CSSPrimitiveValue::CSS_NUMBER)));
     677                result.appendLiteral(", ");
     678                result.append(stop.m_color->cssText());
     679                result.append(')');
     680            }
     681        }
     682    } else {
     683        if (m_repeating)
     684            result.appendLiteral("-webkit-repeating-radial-gradient(");
     685        else
     686            result.appendLiteral("-webkit-radial-gradient(");
     687
     688        if (m_firstX && m_firstY) {
     689            result.append(m_firstX->cssText());
     690            result.append(' ');
     691            result.append(m_firstY->cssText());
     692        } else if (m_firstX)
     693            result.append(m_firstX->cssText());
     694         else if (m_firstY)
     695            result.append(m_firstY->cssText());
     696        else
     697            result.appendLiteral("center");
     698
     699        if (m_shape || m_sizingBehavior) {
     700            result.appendLiteral(", ");
     701            if (m_shape) {
     702                result.append(m_shape->cssText());
     703                result.append(' ');
     704            } else
     705                result.appendLiteral("ellipse ");
     706
     707            if (m_sizingBehavior)
     708                result.append(m_sizingBehavior->cssText());
    646709            else
    647                 result += "color-stop(" + String::number(stop.m_position->getDoubleValue(CSSPrimitiveValue::CSS_NUMBER)) + ", " + stop.m_color->cssText() + ")";
    648         }
    649     } else {
    650 
    651         result = m_repeating ? "-webkit-repeating-radial-gradient(" : "-webkit-radial-gradient(";
    652         if (m_firstX && m_firstY) {
    653             result += m_firstX->cssText() + " " + m_firstY->cssText();
    654         } else if (m_firstX)
    655             result += m_firstX->cssText();
    656          else if (m_firstY)
    657             result += m_firstY->cssText();
    658         else
    659             result += "center";
    660 
    661 
    662         if (m_shape || m_sizingBehavior) {
    663             result += ", ";
    664             if (m_shape)
    665                 result += m_shape->cssText() + " ";
    666             else
    667                 result += "ellipse ";
    668 
    669             if (m_sizingBehavior)
    670                 result += m_sizingBehavior->cssText();
    671             else
    672                 result += "cover";
     710                result.appendLiteral("cover");
    673711
    674712        } else if (m_endHorizontalSize && m_endVerticalSize) {
    675             result += ", ";
    676             result += m_endHorizontalSize->cssText() + " " + m_endVerticalSize->cssText();
     713            result.appendLiteral(", ");
     714            result.append(m_endHorizontalSize->cssText());
     715            result.append(' ');
     716            result.append(m_endVerticalSize->cssText());
    677717        }
    678718
    679719        for (unsigned i = 0; i < m_stops.size(); i++) {
    680720            const CSSGradientColorStop& stop = m_stops[i];
    681             result += ", ";
    682             result += stop.m_color->cssText();
    683             if (stop.m_position)
    684                 result += " " + stop.m_position->cssText();
    685         }
    686     }
    687 
    688     result += ")";
    689     return result;
     721            result.appendLiteral(", ");
     722            result.append(stop.m_color->cssText());
     723            if (stop.m_position) {
     724                result.append(' ');
     725                result.append(stop.m_position->cssText());
     726            }
     727        }
     728    }
     729
     730    result.append(')');
     731    return result.toString();
    690732}
    691733
Note: See TracChangeset for help on using the changeset viewer.