Chromium Code Reviews| Index: Source/wtf/text/StringImpl.cpp |
| diff --git a/Source/wtf/text/StringImpl.cpp b/Source/wtf/text/StringImpl.cpp |
| index cb3bf2352a7c8edf560675ff168adee6a9cc94fa..0152e6447abe125b618b42939391b7005044006b 100644 |
| --- a/Source/wtf/text/StringImpl.cpp |
| +++ b/Source/wtf/text/StringImpl.cpp |
| @@ -502,39 +502,36 @@ PassRefPtr<StringImpl> StringImpl::lower() |
| // no-op code path up through the first 'return' statement. |
| // First scan the string for uppercase and non-ASCII characters: |
| - bool noUpper = true; |
| - UChar ored = 0; |
| if (is8Bit()) { |
| - const LChar* end = characters8() + m_length; |
| - for (const LChar* chp = characters8(); chp != end; ++chp) { |
| - if (UNLIKELY(isASCIIUpper(*chp))) |
| - noUpper = false; |
| - ored |= *chp; |
| + unsigned needsLowering = m_length; |
|
tkent
2015/06/15 01:12:56
The name |needsLowering| sounds a boolean. should
|
| + for (unsigned i = 0; i < m_length; ++i) { |
| + LChar ch = characters8()[i]; |
| + if (UNLIKELY(isASCIIUpper(ch) || ch & ~0x7F)) { |
| + needsLowering = i; |
| + break; |
| + } |
| } |
| + |
| // Nothing to do if the string is all ASCII with no uppercase. |
| - if (noUpper && !(ored & ~0x7F)) |
| + if (needsLowering == m_length) |
| return this; |
| - RELEASE_ASSERT(m_length <= static_cast<unsigned>(numeric_limits<int32_t>::max())); |
| - int32_t length = m_length; |
| - |
| LChar* data8; |
| - RefPtr<StringImpl> newImpl = createUninitialized(length, data8); |
| - |
| - if (!(ored & ~0x7F)) { |
| - for (int32_t i = 0; i < length; ++i) |
| - data8[i] = toASCIILower(characters8()[i]); |
| + RefPtr<StringImpl> newImpl = createUninitialized(m_length, data8); |
| + memcpy(data8, characters8(), needsLowering); |
| - return newImpl.release(); |
| + for (unsigned i = needsLowering; i < m_length; ++i) { |
| + LChar ch = characters8()[i]; |
| + data8[i] = UNLIKELY(ch & ~0x7F) ? static_cast<LChar>(Unicode::toLower(ch)) |
| + : toASCIILower(ch); |
| } |
| - // Do a slower implementation for cases that include non-ASCII Latin-1 characters. |
| - for (int32_t i = 0; i < length; ++i) |
| - data8[i] = static_cast<LChar>(Unicode::toLower(characters8()[i])); |
| - |
| return newImpl.release(); |
| } |
| + bool noUpper = true; |
| + UChar ored = 0; |
| + |
| const UChar* end = characters16() + m_length; |
| for (const UChar* chp = characters16(); chp != end; ++chp) { |
| if (UNLIKELY(isASCIIUpper(*chp))) |