Title: [134981] trunk/Source/WTF
Revision
134981
Author
msab...@apple.com
Date
2012-11-16 12:18:04 -0800 (Fri, 16 Nov 2012)

Log Message

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 in ASCII flag to convertUTF8ToUTF16() and if try, create an 8 bit string from the original arguments.
Relanding after fix to https://bugs.webkit.org/show_bug.cgi?id=102482.

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

Modified Paths

Diff

Modified: trunk/Source/WTF/ChangeLog (134980 => 134981)


--- trunk/Source/WTF/ChangeLog	2012-11-16 20:05:35 UTC (rev 134980)
+++ trunk/Source/WTF/ChangeLog	2012-11-16 20:18:04 UTC (rev 134981)
@@ -1,3 +1,16 @@
+2012-11-16  Michael Saboff  <msab...@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 in ASCII flag to convertUTF8ToUTF16() and if try, create an 8 bit string from the original arguments.
+        Relanding after fix to https://bugs.webkit.org/show_bug.cgi?id=102482.
+
+        * wtf/text/WTFString.cpp:
+        (WTF::String::fromUTF8):
+
 2012-11-15  Yury Semikhatsky  <yu...@chromium.org>
 
         Memory instrumentation: add code for reporting stack traces of unknown instrumented objects

Modified: trunk/Source/WTF/wtf/text/WTFString.cpp (134980 => 134981)


--- trunk/Source/WTF/wtf/text/WTFString.cpp	2012-11-16 20:05:35 UTC (rev 134980)
+++ trunk/Source/WTF/wtf/text/WTFString.cpp	2012-11-16 20:18:04 UTC (rev 134981)
@@ -877,17 +877,24 @@
     if (!stringStart)
         return String();
 
+    if (!length)
+        return emptyString();
+
     // We'll use a StringImpl as a buffer; if the source string only contains ascii this should be
     // the right length, if there are any multi-byte sequences this buffer will be too large.
     UChar* buffer;
     String stringBuffer(StringImpl::createUninitialized(length, buffer));
     UChar* bufferEnd = buffer + 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;
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
http://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to