String::fromUTF8() should take advantage of the ASCII check in convertUTF8ToUTF16()
authormsaboff@apple.com <msaboff@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Sat, 27 Oct 2012 18:25:56 +0000 (18:25 +0000)
committermsaboff@apple.com <msaboff@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Sat, 27 Oct 2012 18:25:56 +0000 (18:25 +0000)
https://bugs.webkit.org/show_bug.cgi?id=100577

Reviewed by Oliver Hunt.

Passed is ASCII flag to convertUTF8ToUTF16() and if try, create an 8 bit string from the original arguments.

* wtf/text/WTFString.cpp:
(WTF::String::fromUTF8):

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@132736 268f45cc-cd09-0410-ab3c-d52691b4dbfc

Source/WTF/ChangeLog
Source/WTF/wtf/text/WTFString.cpp

index c50f014..52b9b4c 100644 (file)
@@ -1,3 +1,15 @@
+2012-10-27  Michael Saboff  <msaboff@apple.com>
+
+        String::fromUTF8() should take advantage of the ASCII check in convertUTF8ToUTF16()
+        https://bugs.webkit.org/show_bug.cgi?id=100577
+
+        Reviewed by Oliver Hunt.
+
+        Passed is ASCII flag to convertUTF8ToUTF16() and if try, create an 8 bit string from the original arguments.
+
+        * wtf/text/WTFString.cpp:
+        (WTF::String::fromUTF8):
+
 2012-10-27  Dan Bernstein  <mitz@apple.com>
 
         REAL_PLATFORM_NAME build setting is no longer needed
index 16a6a45..14e0c80 100644 (file)
@@ -862,9 +862,13 @@ String String::fromUTF8(const LChar* stringStart, size_t length)
 
     // Try converting into the buffer.
     const char* stringCurrent = reinterpret_cast<const char*>(stringStart);
-    if (convertUTF8ToUTF16(&stringCurrent, reinterpret_cast<const char *>(stringStart + length), &buffer, bufferEnd) != conversionOK)
+    bool isAllASCII;
+    if (convertUTF8ToUTF16(&stringCurrent, reinterpret_cast<const char *>(stringStart + length), &buffer, bufferEnd, &isAllASCII) != conversionOK)
         return String();
 
+    if (isAllASCII)
+        return String(stringStart, length);
+
     // stringBuffer is full (the input must have been all ascii) so just return it!
     if (buffer == bufferEnd)
         return stringBuffer;