Ignore:
Timestamp:
Dec 11, 2009, 3:34:10 PM (15 years ago)
Author:
[email protected]
Message:

https://bugs.webkit.org/show_bug.cgi?id=32454
Refactor construction of simple strings to avoid string concatenation.

Reviewed by Oliver Hunt.

Building strings through concatenation has a memory and performance cost -
a memory cost since we must over-allocate the buffer to leave space to append
into, and performance in that the string may still require reallocation (and
thus copying during construction). Instead move the full construction to
within a single function call (makeString), so that the arguments' lengths
can be calculated and an appropriate sized buffer allocated before copying
any characters.

~No performance change (~2% progression on date tests).

  • bytecode/CodeBlock.cpp:

(JSC::escapeQuotes):
(JSC::valueToSourceString):
(JSC::constantName):
(JSC::idName):
(JSC::CodeBlock::registerName):
(JSC::regexpToSourceString):
(JSC::regexpName):

  • bytecompiler/NodesCodegen.cpp:

(JSC::substitute):

  • profiler/Profiler.cpp:

(JSC::Profiler::createCallIdentifier):

  • runtime/DateConstructor.cpp:

(JSC::callDate):

  • runtime/DateConversion.cpp:

(JSC::formatDate):
(JSC::formatDateUTCVariant):
(JSC::formatTime):
(JSC::formatTimeUTC):

  • runtime/DateConversion.h:

(JSC::):

  • runtime/DatePrototype.cpp:

(JSC::dateProtoFuncToString):
(JSC::dateProtoFuncToUTCString):
(JSC::dateProtoFuncToDateString):
(JSC::dateProtoFuncToTimeString):
(JSC::dateProtoFuncToGMTString):

  • runtime/ErrorPrototype.cpp:

(JSC::errorProtoFuncToString):

  • runtime/ExceptionHelpers.cpp:

(JSC::createUndefinedVariableError):
(JSC::createErrorMessage):
(JSC::createInvalidParamError):

  • runtime/FunctionPrototype.cpp:

(JSC::insertSemicolonIfNeeded):
(JSC::functionProtoFuncToString):

  • runtime/ObjectPrototype.cpp:

(JSC::objectProtoFuncToString):

  • runtime/RegExpConstructor.cpp:

(JSC::constructRegExp):

  • runtime/RegExpObject.cpp:

(JSC::RegExpObject::match):

  • runtime/RegExpPrototype.cpp:

(JSC::regExpProtoFuncCompile):
(JSC::regExpProtoFuncToString):

  • runtime/StringPrototype.cpp:

(JSC::stringProtoFuncBig):
(JSC::stringProtoFuncSmall):
(JSC::stringProtoFuncBlink):
(JSC::stringProtoFuncBold):
(JSC::stringProtoFuncFixed):
(JSC::stringProtoFuncItalics):
(JSC::stringProtoFuncStrike):
(JSC::stringProtoFuncSub):
(JSC::stringProtoFuncSup):
(JSC::stringProtoFuncFontcolor):
(JSC::stringProtoFuncFontsize):
(JSC::stringProtoFuncAnchor):

  • runtime/UString.h:

(JSC::):
(JSC::makeString):

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/JavaScriptCore/runtime/DateConversion.cpp

    r50708 r52028  
    6363}
    6464
    65 UString formatDate(const GregorianDateTime &t)
     65void formatDate(const GregorianDateTime &t, DateConversionBuffer& buffer)
    6666{
    67     char buffer[100];
    68     snprintf(buffer, sizeof(buffer), "%s %s %02d %04d",
     67    snprintf(buffer, DateConversionBufferSize, "%s %s %02d %04d",
    6968        weekdayName[(t.weekDay + 6) % 7],
    7069        monthName[t.month], t.monthDay, t.year + 1900);
    71     return buffer;
    7270}
    7371
    74 UString formatDateUTCVariant(const GregorianDateTime &t)
     72void formatDateUTCVariant(const GregorianDateTime &t, DateConversionBuffer& buffer)
    7573{
    76     char buffer[100];
    77     snprintf(buffer, sizeof(buffer), "%s, %02d %s %04d",
     74    snprintf(buffer, DateConversionBufferSize, "%s, %02d %s %04d",
    7875        weekdayName[(t.weekDay + 6) % 7],
    7976        t.monthDay, monthName[t.month], t.year + 1900);
    80     return buffer;
    8177}
    8278
    83 UString formatTime(const GregorianDateTime &t)
     79void formatTime(const GregorianDateTime &t, DateConversionBuffer& buffer)
    8480{
    85     char buffer[100];
    8681    int offset = abs(gmtoffset(t));
    8782    char timeZoneName[70];
     
    9085
    9186    if (timeZoneName[0]) {
    92         snprintf(buffer, sizeof(buffer), "%02d:%02d:%02d GMT%c%02d%02d (%s)",
     87        snprintf(buffer, DateConversionBufferSize, "%02d:%02d:%02d GMT%c%02d%02d (%s)",
    9388            t.hour, t.minute, t.second,
    9489            gmtoffset(t) < 0 ? '-' : '+', offset / (60*60), (offset / 60) % 60, timeZoneName);
    9590    } else {
    96         snprintf(buffer, sizeof(buffer), "%02d:%02d:%02d GMT%c%02d%02d",
     91        snprintf(buffer, DateConversionBufferSize, "%02d:%02d:%02d GMT%c%02d%02d",
    9792            t.hour, t.minute, t.second,
    9893            gmtoffset(t) < 0 ? '-' : '+', offset / (60*60), (offset / 60) % 60);
    9994    }
    100     return UString(buffer);
    10195}
    10296
    103 UString formatTimeUTC(const GregorianDateTime &t)
     97void formatTimeUTC(const GregorianDateTime &t, DateConversionBuffer& buffer)
    10498{
    105     char buffer[100];
    106     snprintf(buffer, sizeof(buffer), "%02d:%02d:%02d GMT", t.hour, t.minute, t.second);
    107     return UString(buffer);
     99    snprintf(buffer, DateConversionBufferSize, "%02d:%02d:%02d GMT", t.hour, t.minute, t.second);
    108100}
    109101
Note: See TracChangeset for help on using the changeset viewer.