Changeset 106167 in webkit


Ignore:
Timestamp:
Jan 27, 2012 4:05:51 PM (12 years ago)
Author:
msaboff@apple.com
Message:

StringProtoFuncToUpperCase should call StringImpl::upper similar to StringProtoToLowerCase
https://bugs.webkit.org/show_bug.cgi?id=76647

Reviewed by Geoffrey Garen.

Changed stringProtoFuncToUpperCase to call StringImpl::upper() is a manor similar
to stringProtoFuncToLowerCase(). Fixed StringImpl::upper() to handle the two
8 bit characters that when converted to upper case become 16 bit characters.

  • runtime/StringPrototype.cpp:

(JSC::stringProtoFuncToLowerCase): Removed extra trailing whitespace.
(JSC::stringProtoFuncToUpperCase):

  • wtf/text/StringImpl.cpp:

(WTF::StringImpl::upper):

Location:
trunk/Source/JavaScriptCore
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/JavaScriptCore/ChangeLog

    r106161 r106167  
     12012-01-27  Michael Saboff  <msaboff@apple.com>
     2
     3        StringProtoFuncToUpperCase should call StringImpl::upper similar to StringProtoToLowerCase
     4        https://bugs.webkit.org/show_bug.cgi?id=76647
     5
     6        Reviewed by Geoffrey Garen.
     7
     8        Changed stringProtoFuncToUpperCase to call StringImpl::upper() is a manor similar
     9        to stringProtoFuncToLowerCase().  Fixed StringImpl::upper() to handle the two
     10        8 bit characters that when converted to upper case become 16 bit characters.
     11
     12        * runtime/StringPrototype.cpp:
     13        (JSC::stringProtoFuncToLowerCase): Removed extra trailing whitespace.
     14        (JSC::stringProtoFuncToUpperCase):
     15        * wtf/text/StringImpl.cpp:
     16        (WTF::StringImpl::upper):
     17
    1182012-01-27  Hajime Morita  <morrita@google.com>
    219
  • trunk/Source/JavaScriptCore/runtime/StringPrototype.cpp

    r105698 r106167  
    11811181        return JSValue::encode(sVal);
    11821182
    1183     StringImpl* ourImpl = s.impl();   
     1183    StringImpl* ourImpl = s.impl();
    11841184    RefPtr<StringImpl> lower = ourImpl->lower();
    11851185    if (ourImpl == lower.get())
     
    12001200        return JSValue::encode(sVal);
    12011201
    1202     const UChar* sData = s.characters();
    1203     Vector<UChar> buffer(sSize);
    1204 
    1205     UChar ored = 0;
    1206     for (int i = 0; i < sSize; i++) {
    1207         UChar c = sData[i];
    1208         ored |= c;
    1209         buffer[i] = toASCIIUpper(c);
    1210     }
    1211     if (!(ored & ~0x7f))
    1212         return JSValue::encode(jsString(exec, UString::adopt(buffer)));
    1213 
    1214     bool error;
    1215     int length = Unicode::toUpper(buffer.data(), sSize, sData, sSize, &error);
    1216     if (error) {
    1217         buffer.resize(length);
    1218         length = Unicode::toUpper(buffer.data(), length, sData, sSize, &error);
    1219         if (error)
    1220             return JSValue::encode(sVal);
    1221     }
    1222     if (length == sSize) {
    1223         if (memcmp(buffer.data(), sData, length * sizeof(UChar)) == 0)
    1224             return JSValue::encode(sVal);
    1225     } else
    1226         buffer.resize(length);
    1227     return JSValue::encode(jsString(exec, UString::adopt(buffer)));
     1202    StringImpl* ourImpl = s.impl();
     1203    RefPtr<StringImpl> upper = ourImpl->upper();
     1204    if (ourImpl == upper.get())
     1205        return JSValue::encode(sVal);
     1206    return JSValue::encode(jsString(exec, UString(upper.release())));
    12281207}
    12291208
  • trunk/Source/JavaScriptCore/wtf/text/StringImpl.cpp

    r106019 r106167  
    364364    int32_t length = m_length;
    365365
     366    const UChar* source16;
     367
    366368    if (is8Bit()) {
    367369        LChar* data8;
     
    379381
    380382        // Do a slower implementation for cases that include non-ASCII Latin-1 characters.
    381         for (int32_t i = 0; i < length; i++)
    382             data8[i] = static_cast<LChar>(Unicode::toUpper(m_data8[i]));
     383        for (int32_t i = 0; i < length; i++) {
     384            UChar upper = Unicode::toUpper(m_data8[i]);
     385            if (UNLIKELY(upper > 0xff)) {
     386                // Have a character that is 16bit when converted to uppercase.
     387                source16 = characters();
     388                goto upconvert;
     389            }
     390               
     391            data8[i] = static_cast<LChar>(upper);
     392        }
    383393
    384394        return newImpl.release();
    385395    }
    386396
     397    source16 = m_data16;
     398
     399upconvert:
    387400    UChar* data16;
    388401    RefPtr<StringImpl> newImpl = createUninitialized(m_length, data16);
     
    391404    UChar ored = 0;
    392405    for (int i = 0; i < length; i++) {
    393         UChar c = m_data16[i];
     406        UChar c = source16[i];
    394407        ored |= c;
    395408        data16[i] = toASCIIUpper(c);
     
    401414    bool error;
    402415    newImpl = createUninitialized(m_length, data16);
    403     int32_t realLength = Unicode::toUpper(data16, length, m_data16, m_length, &error);
     416    int32_t realLength = Unicode::toUpper(data16, length, source16, m_length, &error);
    404417    if (!error && realLength == length)
    405418        return newImpl;
    406419    newImpl = createUninitialized(realLength, data16);
    407     Unicode::toUpper(data16, realLength, m_data16, m_length, &error);
     420    Unicode::toUpper(data16, realLength, source16, m_length, &error);
    408421    if (error)
    409422        return this;
Note: See TracChangeset for help on using the changeset viewer.