Title: [101186] trunk/Source/_javascript_Core
Revision
101186
Author
msab...@apple.com
Date
2011-11-25 22:01:06 -0800 (Fri, 25 Nov 2011)

Log Message

Array.toString always uses StringImpl::characters()
https://bugs.webkit.org/show_bug.cgi?id=72969

If all component strings are 8 bit, create an 8 bit result string for toString().

This appears to be performance neutral to sunspider and v8.

Reviewed by Filip Pizlo.

* runtime/ArrayPrototype.cpp:
(JSC::arrayProtoFuncToString):

Modified Paths

Diff

Modified: trunk/Source/_javascript_Core/ChangeLog (101185 => 101186)


--- trunk/Source/_javascript_Core/ChangeLog	2011-11-26 04:28:39 UTC (rev 101185)
+++ trunk/Source/_javascript_Core/ChangeLog	2011-11-26 06:01:06 UTC (rev 101186)
@@ -1,3 +1,17 @@
+2011-11-25  Michael Saboff  <msab...@apple.com>
+
+        Array.toString always uses StringImpl::characters()
+        https://bugs.webkit.org/show_bug.cgi?id=72969
+
+        If all component strings are 8 bit, create an 8 bit result string for toString().
+
+        This appears to be performance neutral to sunspider and v8.
+
+        Reviewed by Filip Pizlo.
+
+        * runtime/ArrayPrototype.cpp:
+        (JSC::arrayProtoFuncToString):
+
 2011-11-24  Michael Saboff  <msab...@apple.com>
 
         UString methods are not character size aware

Modified: trunk/Source/_javascript_Core/runtime/ArrayPrototype.cpp (101185 => 101186)


--- trunk/Source/_javascript_Core/runtime/ArrayPrototype.cpp	2011-11-26 04:28:39 UTC (rev 101185)
+++ trunk/Source/_javascript_Core/runtime/ArrayPrototype.cpp	2011-11-26 06:01:06 UTC (rev 101186)
@@ -185,6 +185,7 @@
 
     unsigned totalSize = length ? length - 1 : 0;
     Vector<RefPtr<StringImpl>, 256> strBuffer(length);
+    bool allStrings8Bit = true;
 
     for (unsigned k = 0; k < length; k++) {
         JSValue element;
@@ -199,6 +200,7 @@
         UString str = element.toString(exec);
         strBuffer[k] = str.impl();
         totalSize += str.length();
+        allStrings8Bit = allStrings8Bit && str.is8Bit();
         
         if (!strBuffer.data()) {
             throwOutOfMemoryError(exec);
@@ -209,6 +211,23 @@
     }
     if (!totalSize)
         return JSValue::encode(jsEmptyString(exec));
+
+    if (allStrings8Bit) {
+        Vector<LChar> buffer;
+        buffer.reserveCapacity(totalSize);
+        if (!buffer.data())
+            return JSValue::encode(throwOutOfMemoryError(exec));
+        
+        for (unsigned i = 0; i < length; i++) {
+            if (i)
+                buffer.append(',');
+            if (RefPtr<StringImpl> rep = strBuffer[i])
+                buffer.append(rep->characters8(), rep->length());
+        }
+        ASSERT(buffer.size() == totalSize);
+        return JSValue::encode(jsString(exec, UString::adopt(buffer)));        
+    }
+
     Vector<UChar> buffer;
     buffer.reserveCapacity(totalSize);
     if (!buffer.data())
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
http://lists.webkit.org/mailman/listinfo.cgi/webkit-changes

Reply via email to