Changeset 52028 in webkit for trunk/JavaScriptCore/bytecode


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/bytecode/CodeBlock.cpp

    r51735 r52028  
    5252    int pos = 0;
    5353    while ((pos = result.find('\"', pos)) >= 0) {
    54         result = result.substr(0, pos) + "\"\\\"\"" + result.substr(pos + 1);
     54        result = makeString(result.substr(0, pos), "\"\\\"\"", result.substr(pos + 1));
    5555        pos += 4;
    5656    }
     
    6363        return "0";
    6464
    65     if (val.isString()) {
    66         UString result("\"");
    67         result += escapeQuotes(val.toString(exec)) + "\"";
    68         return result;
    69     }
     65    if (val.isString())
     66        return makeString("\"", escapeQuotes(val.toString(exec)), "\"");
    7067
    7168    return val.toString(exec);
     
    7471static CString constantName(ExecState* exec, int k, JSValue value)
    7572{
    76     return (valueToSourceString(exec, value) + "(@k" + UString::from(k - FirstConstantRegisterIndex) + ")").UTF8String();
     73    return makeString(valueToSourceString(exec, value), "(@k", UString::from(k - FirstConstantRegisterIndex), ")").UTF8String();
    7774}
    7875
    7976static CString idName(int id0, const Identifier& ident)
    8077{
    81     return (ident.ustring() + "(@id" + UString::from(id0) +")").UTF8String();
     78    return makeString(ident.ustring(), "(@id", UString::from(id0), ")").UTF8String();
    8279}
    8380
     
    9087        return constantName(exec, r, getConstant(r));
    9188
    92     return (UString("r") + UString::from(r)).UTF8String();
     89    return makeString("r", UString::from(r)).UTF8String();
    9390}
    9491
    9592static UString regexpToSourceString(RegExp* regExp)
    9693{
    97     UString pattern = UString("/") + regExp->pattern() + "/";
     94    char postfix[5] = { '/', 0, 0, 0, 0 };
     95    int index = 1;
    9896    if (regExp->global())
    99         pattern += "g";
     97        postfix[index++] = 'g';
    10098    if (regExp->ignoreCase())
    101         pattern += "i";
     99        postfix[index++] = 'i';
    102100    if (regExp->multiline())
    103         pattern += "m";
    104 
    105     return pattern;
     101        postfix[index] = 'm';
     102
     103    return makeString("/", regExp->pattern(), postfix);
    106104}
    107105
    108106static CString regexpName(int re, RegExp* regexp)
    109107{
    110     return (regexpToSourceString(regexp) + "(@re" + UString::from(re) + ")").UTF8String();
     108    return makeString(regexpToSourceString(regexp), "(@re", UString::from(re), ")").UTF8String();
    111109}
    112110
Note: See TracChangeset for help on using the changeset viewer.