Title: [106167] trunk/Source/_javascript_Core
Revision
106167
Author
msab...@apple.com
Date
2012-01-27 16:05:51 -0800 (Fri, 27 Jan 2012)

Log 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):

Modified Paths

Diff

Modified: trunk/Source/_javascript_Core/ChangeLog (106166 => 106167)


--- trunk/Source/_javascript_Core/ChangeLog	2012-01-28 00:05:00 UTC (rev 106166)
+++ trunk/Source/_javascript_Core/ChangeLog	2012-01-28 00:05:51 UTC (rev 106167)
@@ -1,3 +1,20 @@
+2012-01-27  Michael Saboff  <msab...@apple.com>
+
+        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):
+
 2012-01-27  Hajime Morita  <morr...@google.com>
 
         [JSC] ThunkGenerators.cpp should hide its asm-defined symbols

Modified: trunk/Source/_javascript_Core/runtime/StringPrototype.cpp (106166 => 106167)


--- trunk/Source/_javascript_Core/runtime/StringPrototype.cpp	2012-01-28 00:05:00 UTC (rev 106166)
+++ trunk/Source/_javascript_Core/runtime/StringPrototype.cpp	2012-01-28 00:05:51 UTC (rev 106167)
@@ -1180,7 +1180,7 @@
     if (!sSize)
         return JSValue::encode(sVal);
 
-    StringImpl* ourImpl = s.impl();   
+    StringImpl* ourImpl = s.impl();
     RefPtr<StringImpl> lower = ourImpl->lower();
     if (ourImpl == lower.get())
         return JSValue::encode(sVal);
@@ -1199,32 +1199,11 @@
     if (!sSize)
         return JSValue::encode(sVal);
 
-    const UChar* sData = s.characters();
-    Vector<UChar> buffer(sSize);
-
-    UChar ored = 0;
-    for (int i = 0; i < sSize; i++) {
-        UChar c = sData[i];
-        ored |= c;
-        buffer[i] = toASCIIUpper(c);
-    }
-    if (!(ored & ~0x7f))
-        return JSValue::encode(jsString(exec, UString::adopt(buffer)));
-
-    bool error;
-    int length = Unicode::toUpper(buffer.data(), sSize, sData, sSize, &error);
-    if (error) {
-        buffer.resize(length);
-        length = Unicode::toUpper(buffer.data(), length, sData, sSize, &error);
-        if (error)
-            return JSValue::encode(sVal);
-    }
-    if (length == sSize) {
-        if (memcmp(buffer.data(), sData, length * sizeof(UChar)) == 0)
-            return JSValue::encode(sVal);
-    } else
-        buffer.resize(length);
-    return JSValue::encode(jsString(exec, UString::adopt(buffer)));
+    StringImpl* ourImpl = s.impl();
+    RefPtr<StringImpl> upper = ourImpl->upper();
+    if (ourImpl == upper.get())
+        return JSValue::encode(sVal);
+    return JSValue::encode(jsString(exec, UString(upper.release())));
 }
 
 EncodedJSValue JSC_HOST_CALL stringProtoFuncLocaleCompare(ExecState* exec)

Modified: trunk/Source/_javascript_Core/wtf/text/StringImpl.cpp (106166 => 106167)


--- trunk/Source/_javascript_Core/wtf/text/StringImpl.cpp	2012-01-28 00:05:00 UTC (rev 106166)
+++ trunk/Source/_javascript_Core/wtf/text/StringImpl.cpp	2012-01-28 00:05:51 UTC (rev 106167)
@@ -363,6 +363,8 @@
         CRASH();
     int32_t length = m_length;
 
+    const UChar* source16;
+
     if (is8Bit()) {
         LChar* data8;
         RefPtr<StringImpl> newImpl = createUninitialized(m_length, data8);
@@ -378,19 +380,30 @@
             return newImpl.release();
 
         // 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::toUpper(m_data8[i]));
+        for (int32_t i = 0; i < length; i++) {
+            UChar upper = Unicode::toUpper(m_data8[i]);
+            if (UNLIKELY(upper > 0xff)) {
+                // Have a character that is 16bit when converted to uppercase.
+                source16 = characters();
+                goto upconvert;
+            }
+                
+            data8[i] = static_cast<LChar>(upper);
+        }
 
         return newImpl.release();
     }
 
+    source16 = m_data16;
+
+upconvert:
     UChar* data16;
     RefPtr<StringImpl> newImpl = createUninitialized(m_length, data16);
     
     // Do a faster loop for the case where all the characters are ASCII.
     UChar ored = 0;
     for (int i = 0; i < length; i++) {
-        UChar c = m_data16[i];
+        UChar c = source16[i];
         ored |= c;
         data16[i] = toASCIIUpper(c);
     }
@@ -400,11 +413,11 @@
     // Do a slower implementation for cases that include non-ASCII characters.
     bool error;
     newImpl = createUninitialized(m_length, data16);
-    int32_t realLength = Unicode::toUpper(data16, length, m_data16, m_length, &error);
+    int32_t realLength = Unicode::toUpper(data16, length, source16, m_length, &error);
     if (!error && realLength == length)
         return newImpl;
     newImpl = createUninitialized(realLength, data16);
-    Unicode::toUpper(data16, realLength, m_data16, m_length, &error);
+    Unicode::toUpper(data16, realLength, source16, m_length, &error);
     if (error)
         return this;
     return newImpl.release();
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
http://lists.webkit.org/mailman/listinfo.cgi/webkit-changes

Reply via email to