Commit db5e0319 authored by mjs@apple.com's avatar mjs@apple.com

2009-04-30 Maciej Stachowiak <mjs@apple.com>

        Reviewed by Gavin Barraclough.

        - Concatenate final three strings in simple replace case at one go

        ~0.2% SunSpider speedup

        * runtime/StringPrototype.cpp:
        (JSC::stringProtoFuncReplace): Use new replaceRange helper instead of
        taking substrings and concatenating three strings.
        * runtime/UString.cpp:
        (JSC::UString::replaceRange): New helper function.
        * runtime/UString.h:



git-svn-id: http://svn.webkit.org/repository/webkit/trunk@43104 268f45cc-cd09-0410-ab3c-d52691b4dbfc
parent 5368abca
2009-04-30 Maciej Stachowiak <mjs@apple.com>
Reviewed by Gavin Barraclough.
- Concatenate final three strings in simple replace case at one go
~0.2% SunSpider speedup
* runtime/StringPrototype.cpp:
(JSC::stringProtoFuncReplace): Use new replaceRange helper instead of
taking substrings and concatenating three strings.
* runtime/UString.cpp:
(JSC::UString::replaceRange): New helper function.
* runtime/UString.h:
2009-04-30 Geoffrey Garen <ggaren@apple.com>
Rubber Stamped by Gavin Barraclough.
......@@ -351,9 +351,7 @@ JSValuePtr stringProtoFuncReplace(ExecState* exec, JSObject*, JSValuePtr thisVal
}
int ovector[2] = { matchPos, matchPos + matchLen };
return jsString(exec, source.substr(0, matchPos)
+ substituteBackreferences(replacementString, source, ovector, 0)
+ source.substr(matchPos + matchLen));
return jsString(exec, source.replaceRange(matchPos, matchLen, substituteBackreferences(replacementString, source, ovector, 0)));
}
JSValuePtr stringProtoFuncToString(ExecState* exec, JSObject*, JSValuePtr thisValue, const ArgList&)
......
......@@ -981,6 +981,28 @@ UString UString::spliceSubstringsWithSeparators(const Range* substringRanges, in
return UString::Rep::create(buffer, totalLength);
}
UString UString::replaceRange(int rangeStart, int rangeLength, const UString& replacement) const
{
m_rep->checkConsistency();
int replacementLength = replacement.size();
int totalLength = size() - rangeLength + replacementLength;
if (totalLength == 0)
return "";
UChar* buffer = allocChars(totalLength);
if (!buffer)
return null();
copyChars(buffer, data(), rangeStart);
copyChars(buffer + rangeStart, replacement.data(), replacementLength);
int rangeEnd = rangeStart + rangeLength;
copyChars(buffer + rangeStart + replacementLength, data() + rangeEnd, size() - rangeEnd);
return UString::Rep::create(buffer, totalLength);
}
UString& UString::append(const UString &t)
{
m_rep->checkConsistency();
......
......@@ -244,6 +244,8 @@ namespace JSC {
UString spliceSubstringsWithSeparators(const Range* substringRanges, int rangeCount, const UString* separators, int separatorCount) const;
UString replaceRange(int rangeStart, int RangeEnd, const UString& replacement) const;
UString& append(const UString&);
UString& append(const char*);
UString& append(UChar);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment