Simplify & optimize StringImpl::replace(UChar, UChar)

StringImpl::replace(UChar, UChar) is mentioned as one of the
hot spots by the Intel VTune Amplifier profile when running
the 'textarea-dom.html' performance test.

StringImpl::replace(UChar, UChar) is optimized (and simplified)
by using 'StringImpl::find' method instead of manual traversing
the internal buffer and checking 'is8Bit' property value on
each iteration.

This changes gives approx 2.25% improvement of the average
'textarea-dom.html' performance test results (linux desktop x64,
GCC 4.6.3, release content_shell build with enabled
'linux_dump_symbols' flag).

Review URL: https://codereview.chromium.org/304273003

git-svn-id: svn://svn.chromium.org/blink/trunk@175198 bbb929c8-8fbe-4397-9dbb-9b2b20218538
parent 41c37b46
...@@ -1529,20 +1529,12 @@ PassRefPtr<StringImpl> StringImpl::replace(UChar oldC, UChar newC) ...@@ -1529,20 +1529,12 @@ PassRefPtr<StringImpl> StringImpl::replace(UChar oldC, UChar newC)
{ {
if (oldC == newC) if (oldC == newC)
return this; return this;
unsigned i;
for (i = 0; i != m_length; ++i) { if (find(oldC) == kNotFound)
UChar c = is8Bit() ? characters8()[i] : characters16()[i];
if (c == oldC)
break;
}
if (i == m_length)
return this; return this;
unsigned i;
if (is8Bit()) { if (is8Bit()) {
if (oldC > 0xff)
// Looking for a 16 bit char in an 8 bit string, we're done.
return this;
if (newC <= 0xff) { if (newC <= 0xff) {
LChar* data; LChar* data;
LChar oldChar = static_cast<LChar>(oldC); LChar oldChar = static_cast<LChar>(oldC);
......
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