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
+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.
}
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&)
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();
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);