Title: [102380] trunk/Source/_javascript_Core
Revision
102380
Author
msab...@apple.com
Date
2011-12-08 13:47:42 -0800 (Thu, 08 Dec 2011)

Log Message

Add 8 bit paths for StringTypeAdapter classes
https://bugs.webkit.org/show_bug.cgi?id=73882

Reviewed by Darin Adler.

Added is8Bit() method and writeTo(LChar*) methods
to StringTypeAdapter<> classes.  The writeTo(LChar*)
method can be used if is8Bit() returns true.  The
non-native 8 bit classes contain ASSERT(is8Bit())
in their writeTo(LChar*).

Updated all of the various versions of tryMakeString() to
use 8 bit processing in the updated StringTypeAdapter<>
classes.

This has slight if any performance improvement on kraken.

* runtime/UStringConcatenate.h:
* wtf/text/StringConcatenate.h:
(WTF::tryMakeString):
* wtf/text/StringOperators.h:
(WTF::StringAppend::is8Bit):
(WTF::StringAppend::writeTo):

Modified Paths

Diff

Modified: trunk/Source/_javascript_Core/ChangeLog (102379 => 102380)


--- trunk/Source/_javascript_Core/ChangeLog	2011-12-08 21:29:31 UTC (rev 102379)
+++ trunk/Source/_javascript_Core/ChangeLog	2011-12-08 21:47:42 UTC (rev 102380)
@@ -1,3 +1,29 @@
+2011-12-08  Michael Saboff  <msab...@apple.com>
+
+        Add 8 bit paths for StringTypeAdapter classes
+        https://bugs.webkit.org/show_bug.cgi?id=73882
+
+        Reviewed by Darin Adler.
+
+        Added is8Bit() method and writeTo(LChar*) methods
+        to StringTypeAdapter<> classes.  The writeTo(LChar*)
+        method can be used if is8Bit() returns true.  The
+        non-native 8 bit classes contain ASSERT(is8Bit())
+        in their writeTo(LChar*).
+
+        Updated all of the various versions of tryMakeString() to
+        use 8 bit processing in the updated StringTypeAdapter<>
+        classes.
+
+        This has slight if any performance improvement on kraken.
+
+        * runtime/UStringConcatenate.h:
+        * wtf/text/StringConcatenate.h:
+        (WTF::tryMakeString):
+        * wtf/text/StringOperators.h:
+        (WTF::StringAppend::is8Bit):
+        (WTF::StringAppend::writeTo):
+
 2011-12-07  Filip Pizlo  <fpi...@apple.com>
 
         DFG CSE should know that CheckFunction is pure

Modified: trunk/Source/_javascript_Core/runtime/UStringConcatenate.h (102379 => 102380)


--- trunk/Source/_javascript_Core/runtime/UStringConcatenate.h	2011-12-08 21:29:31 UTC (rev 102379)
+++ trunk/Source/_javascript_Core/runtime/UStringConcatenate.h	2011-12-08 21:47:42 UTC (rev 102380)
@@ -35,21 +35,37 @@
 class StringTypeAdapter<JSC::UString> {
 public:
     StringTypeAdapter<JSC::UString>(JSC::UString& string)
-        : m_data(string.characters())
+        : m_string(string)
         , m_length(string.length())
     {
     }
 
     unsigned length() { return m_length; }
 
-    void writeTo(UChar* destination)
+    bool is8Bit() { return m_string.isNull() || m_string.is8Bit(); }
+
+    void writeTo(LChar* destination)
     {
+        const LChar* characters = m_string.characters8();
         for (unsigned i = 0; i < m_length; ++i)
-            destination[i] = m_data[i];
+            destination[i] = characters[i];
     }
 
+    void writeTo(UChar* destination)
+    {
+        if (is8Bit()) {
+            const LChar* characters = m_string.characters8();
+            for (unsigned i = 0; i < m_length; ++i)
+                destination[i] = characters[i];
+        } else {
+            const UChar* characters = m_string.characters16();
+            for (unsigned i = 0; i < m_length; ++i)
+                destination[i] = characters[i];
+        }
+    }
+
 private:
-    const UChar* m_data;
+    const JSC::UString& m_string;
     unsigned m_length;
 };
 

Modified: trunk/Source/_javascript_Core/wtf/text/StringConcatenate.h (102379 => 102380)


--- trunk/Source/_javascript_Core/wtf/text/StringConcatenate.h	2011-12-08 21:29:31 UTC (rev 102379)
+++ trunk/Source/_javascript_Core/wtf/text/StringConcatenate.h	2011-12-08 21:47:42 UTC (rev 102380)
@@ -51,6 +51,14 @@
     }
 
     unsigned length() { return 1; }
+
+    bool is8Bit() { return true; }
+
+    void writeTo(LChar* destination)
+    {
+        *destination = m_buffer;
+    }
+
     void writeTo(UChar* destination) { *destination = m_buffer; }
 
 private:
@@ -66,6 +74,14 @@
     }
 
     unsigned length() { return 1; }
+
+    bool is8Bit() { return true; }
+
+    void writeTo(LChar* destination)
+    {
+        *destination = m_buffer;
+    }
+
     void writeTo(UChar* destination) { *destination = m_buffer; }
 
 private:
@@ -81,6 +97,15 @@
     }
 
     unsigned length() { return 1; }
+
+    bool is8Bit() { return m_buffer <= 0xff; }
+
+    void writeTo(LChar* destination)
+    {
+        ASSERT(is8Bit());
+        *destination = static_cast<LChar>(m_buffer);
+    }
+
     void writeTo(UChar* destination) { *destination = m_buffer; }
 
 private:
@@ -98,6 +123,14 @@
 
     unsigned length() { return m_length; }
 
+    bool is8Bit() { return true; }
+
+    void writeTo(LChar* destination)
+    {
+        for (unsigned i = 0; i < m_length; ++i)
+            destination[i] = static_cast<LChar>(m_buffer[i]);
+    }
+
     void writeTo(UChar* destination)
     {
         for (unsigned i = 0; i < m_length; ++i) {
@@ -122,6 +155,13 @@
 
     unsigned length() { return m_length; }
 
+    bool is8Bit() { return true; }
+
+    void writeTo(LChar* destination)
+    {
+        memcpy(destination, m_buffer, m_length * sizeof(LChar));
+    }
+
     void writeTo(UChar* destination)
     {
         for (unsigned i = 0; i < m_length; ++i)
@@ -151,9 +191,16 @@
 
     unsigned length() { return m_length; }
 
+    bool is8Bit() { return false; }
+
+    NO_RETURN_DUE_TO_CRASH void writeTo(LChar*)
+    {
+        CRASH();
+    }
+
     void writeTo(UChar* destination)
     {
-        memcpy(destination, m_buffer, static_cast<size_t>(m_length) * sizeof(UChar));
+        memcpy(destination, m_buffer, m_length * sizeof(UChar));
     }
 
 private:
@@ -172,6 +219,13 @@
 
     unsigned length() { return m_length; }
 
+    bool is8Bit() { return true; }
+
+    void writeTo(LChar* destination)
+    {
+        memcpy(destination, m_buffer, static_cast<size_t>(m_length) * sizeof(LChar));
+    }
+
     void writeTo(UChar* destination)
     {
         for (unsigned i = 0; i < m_length; ++i) {
@@ -193,15 +247,22 @@
         , m_length(strlen(reinterpret_cast<const char*>(buffer)))
     {
     }
-    
+
     unsigned length() { return m_length; }
-    
+
+    bool is8Bit() { return true; }
+
+    void writeTo(LChar* destination)
+    {
+        memcpy(destination, m_buffer, static_cast<size_t>(m_length) * sizeof(LChar));
+    }
+
     void writeTo(UChar* destination)
     {
         for (unsigned i = 0; i < m_length; ++i)
             destination[i] = m_buffer[i];
     }
-    
+
 private:
     const LChar* m_buffer;
     unsigned m_length;
@@ -217,12 +278,18 @@
 
     size_t length() { return m_buffer.size(); }
 
+    bool is8Bit() { return true; }
+
+    void writeTo(LChar* destination)
+    {
+        for (size_t i = 0; i < m_buffer.size(); ++i)
+            destination[i] = static_cast<unsigned char>(m_buffer[i]);
+    }
+
     void writeTo(UChar* destination)
     {
-        for (size_t i = 0; i < m_buffer.size(); ++i) {
-            unsigned char c = m_buffer[i];
-            destination[i] = c;
-        }
+        for (size_t i = 0; i < m_buffer.size(); ++i)
+            destination[i] = static_cast<unsigned char>(m_buffer[i]);
     }
 
 private:
@@ -239,6 +306,14 @@
 
     size_t length() { return m_buffer.size(); }
 
+    bool is8Bit() { return true; }
+
+    void writeTo(LChar* destination)
+    {
+        for (size_t i = 0; i < m_buffer.size(); ++i)
+            destination[i] = m_buffer[i];
+    }
+
     void writeTo(UChar* destination)
     {
         for (size_t i = 0; i < m_buffer.size(); ++i)
@@ -259,13 +334,34 @@
 
     unsigned length() { return m_buffer.length(); }
 
-    void writeTo(UChar* destination)
+    bool is8Bit() { return m_buffer.isNull() || m_buffer.is8Bit(); }
+
+    void writeTo(LChar* destination)
     {
-        const UChar* data = ""
         unsigned length = m_buffer.length();
+
+        ASSERT(is8Bit());
+        const LChar* data = ""
         for (unsigned i = 0; i < length; ++i)
             destination[i] = data[i];
+        
+        WTF_STRINGTYPEADAPTER_COPIED_WTF_STRING();
+    }
 
+    void writeTo(UChar* destination)
+    {
+        unsigned length = m_buffer.length();
+
+        if (is8Bit()) {
+            const LChar* data = ""
+            for (unsigned i = 0; i < length; ++i)
+                destination[i] = data[i];
+        } else {
+            const UChar* data = ""
+            for (unsigned i = 0; i < length; ++i)
+                destination[i] = data[i];
+        }
+        
         WTF_STRINGTYPEADAPTER_COPIED_WTF_STRING();
     }
 
@@ -282,6 +378,10 @@
     }
 
     unsigned length() { return m_adapter.length(); }
+
+    bool is8Bit() { return m_adapter.is8Bit(); }
+
+    void writeTo(LChar* destination) { m_adapter.writeTo(destination); }
     void writeTo(UChar* destination) { m_adapter.writeTo(destination); }
 
 private:
@@ -302,12 +402,27 @@
     StringTypeAdapter<StringType1> adapter1(string1);
     StringTypeAdapter<StringType2> adapter2(string2);
 
-    UChar* buffer;
     bool overflow = false;
     unsigned length = adapter1.length();
     sumWithOverflow(length, adapter2.length(), overflow);
     if (overflow)
         return 0;
+
+    if (adapter1.is8Bit() && adapter2.is8Bit()) {
+        LChar* buffer;
+        RefPtr<StringImpl> resultImpl = StringImpl::tryCreateUninitialized(length, buffer);
+        if (!resultImpl)
+            return 0;
+
+        LChar* result = buffer;
+        adapter1.writeTo(result);
+        result += adapter1.length();
+        adapter2.writeTo(result);
+
+        return resultImpl.release();
+    }
+
+    UChar* buffer;
     RefPtr<StringImpl> resultImpl = StringImpl::tryCreateUninitialized(length, buffer);
     if (!resultImpl)
         return 0;
@@ -327,13 +442,30 @@
     StringTypeAdapter<StringType2> adapter2(string2);
     StringTypeAdapter<StringType3> adapter3(string3);
 
-    UChar* buffer = 0;
     bool overflow = false;
     unsigned length = adapter1.length();
     sumWithOverflow(length, adapter2.length(), overflow);
     sumWithOverflow(length, adapter3.length(), overflow);
     if (overflow)
         return 0;
+
+    if (adapter1.is8Bit() && adapter2.is8Bit() && adapter3.is8Bit()) {
+        LChar* buffer;
+        RefPtr<StringImpl> resultImpl = StringImpl::tryCreateUninitialized(length, buffer);
+        if (!resultImpl)
+            return 0;
+
+        LChar* result = buffer;
+        adapter1.writeTo(result);
+        result += adapter1.length();
+        adapter2.writeTo(result);
+        result += adapter2.length();
+        adapter3.writeTo(result);
+
+        return resultImpl.release();
+    }
+
+    UChar* buffer = 0;
     RefPtr<StringImpl> resultImpl = StringImpl::tryCreateUninitialized(length, buffer);
     if (!resultImpl)
         return 0;
@@ -356,7 +488,6 @@
     StringTypeAdapter<StringType3> adapter3(string3);
     StringTypeAdapter<StringType4> adapter4(string4);
 
-    UChar* buffer;
     bool overflow = false;
     unsigned length = adapter1.length();
     sumWithOverflow(length, adapter2.length(), overflow);
@@ -364,6 +495,26 @@
     sumWithOverflow(length, adapter4.length(), overflow);
     if (overflow)
         return 0;
+
+    if (adapter1.is8Bit() && adapter2.is8Bit() && adapter3.is8Bit() && adapter4.is8Bit()) {
+        LChar* buffer;
+        RefPtr<StringImpl> resultImpl = StringImpl::tryCreateUninitialized(length, buffer);
+        if (!resultImpl)
+            return 0;
+
+        LChar* result = buffer;
+        adapter1.writeTo(result);
+        result += adapter1.length();
+        adapter2.writeTo(result);
+        result += adapter2.length();
+        adapter3.writeTo(result);
+        result += adapter3.length();
+        adapter4.writeTo(result);
+
+        return resultImpl.release();
+    }
+
+    UChar* buffer;
     RefPtr<StringImpl> resultImpl = StringImpl::tryCreateUninitialized(length, buffer);
     if (!resultImpl)
         return 0;
@@ -389,7 +540,6 @@
     StringTypeAdapter<StringType4> adapter4(string4);
     StringTypeAdapter<StringType5> adapter5(string5);
 
-    UChar* buffer;
     bool overflow = false;
     unsigned length = adapter1.length();
     sumWithOverflow(length, adapter2.length(), overflow);
@@ -398,6 +548,28 @@
     sumWithOverflow(length, adapter5.length(), overflow);
     if (overflow)
         return 0;
+
+    if (adapter1.is8Bit() && adapter2.is8Bit() && adapter3.is8Bit() && adapter4.is8Bit() && adapter5.is8Bit()) {
+        LChar* buffer;
+        RefPtr<StringImpl> resultImpl = StringImpl::tryCreateUninitialized(length, buffer);
+        if (!resultImpl)
+            return 0;
+
+        LChar* result = buffer;
+        adapter1.writeTo(result);
+        result += adapter1.length();
+        adapter2.writeTo(result);
+        result += adapter2.length();
+        adapter3.writeTo(result);
+        result += adapter3.length();
+        adapter4.writeTo(result);
+        result += adapter4.length();
+        adapter5.writeTo(result);
+
+        return resultImpl.release();
+    }
+
+    UChar* buffer;
     RefPtr<StringImpl> resultImpl = StringImpl::tryCreateUninitialized(length, buffer);
     if (!resultImpl)
         return 0;
@@ -426,7 +598,6 @@
     StringTypeAdapter<StringType5> adapter5(string5);
     StringTypeAdapter<StringType6> adapter6(string6);
 
-    UChar* buffer;
     bool overflow = false;
     unsigned length = adapter1.length();
     sumWithOverflow(length, adapter2.length(), overflow);
@@ -436,6 +607,30 @@
     sumWithOverflow(length, adapter6.length(), overflow);
     if (overflow)
         return 0;
+
+    if (adapter1.is8Bit() && adapter2.is8Bit() && adapter3.is8Bit() && adapter4.is8Bit() && adapter5.is8Bit() && adapter6.is8Bit()) {
+        LChar* buffer;
+        RefPtr<StringImpl> resultImpl = StringImpl::tryCreateUninitialized(length, buffer);
+        if (!resultImpl)
+            return 0;
+
+        LChar* result = buffer;
+        adapter1.writeTo(result);
+        result += adapter1.length();
+        adapter2.writeTo(result);
+        result += adapter2.length();
+        adapter3.writeTo(result);
+        result += adapter3.length();
+        adapter4.writeTo(result);
+        result += adapter4.length();
+        adapter5.writeTo(result);
+        result += adapter5.length();
+        adapter6.writeTo(result);
+
+        return resultImpl.release();        
+    }
+
+    UChar* buffer;
     RefPtr<StringImpl> resultImpl = StringImpl::tryCreateUninitialized(length, buffer);
     if (!resultImpl)
         return 0;
@@ -467,7 +662,6 @@
     StringTypeAdapter<StringType6> adapter6(string6);
     StringTypeAdapter<StringType7> adapter7(string7);
 
-    UChar* buffer;
     bool overflow = false;
     unsigned length = adapter1.length();
     sumWithOverflow(length, adapter2.length(), overflow);
@@ -478,6 +672,32 @@
     sumWithOverflow(length, adapter7.length(), overflow);
     if (overflow)
         return 0;
+
+    if (adapter1.is8Bit() && adapter2.is8Bit() && adapter3.is8Bit() && adapter4.is8Bit() && adapter5.is8Bit() && adapter6.is8Bit()) {
+        LChar* buffer;
+        RefPtr<StringImpl> resultImpl = StringImpl::tryCreateUninitialized(length, buffer);
+        if (!resultImpl)
+            return 0;
+
+        LChar* result = buffer;
+        adapter1.writeTo(result);
+        result += adapter1.length();
+        adapter2.writeTo(result);
+        result += adapter2.length();
+        adapter3.writeTo(result);
+        result += adapter3.length();
+        adapter4.writeTo(result);
+        result += adapter4.length();
+        adapter5.writeTo(result);
+        result += adapter5.length();
+        adapter6.writeTo(result);
+        result += adapter6.length();
+        adapter7.writeTo(result);
+
+        return resultImpl.release();
+    }
+
+    UChar* buffer;
     RefPtr<StringImpl> resultImpl = StringImpl::tryCreateUninitialized(length, buffer);
     if (!resultImpl)
         return 0;
@@ -512,7 +732,6 @@
     StringTypeAdapter<StringType7> adapter7(string7);
     StringTypeAdapter<StringType8> adapter8(string8);
 
-    UChar* buffer;
     bool overflow = false;
     unsigned length = adapter1.length();
     sumWithOverflow(length, adapter2.length(), overflow);
@@ -524,6 +743,34 @@
     sumWithOverflow(length, adapter8.length(), overflow);
     if (overflow)
         return 0;
+
+    if (adapter1.is8Bit() && adapter2.is8Bit() && adapter3.is8Bit() && adapter4.is8Bit() && adapter5.is8Bit() && adapter6.is8Bit() && adapter7.is8Bit() && adapter8.is8Bit()) {
+        LChar* buffer;
+        RefPtr<StringImpl> resultImpl = StringImpl::tryCreateUninitialized(length, buffer);
+        if (!resultImpl)
+            return 0;
+
+        LChar* result = buffer;
+        adapter1.writeTo(result);
+        result += adapter1.length();
+        adapter2.writeTo(result);
+        result += adapter2.length();
+        adapter3.writeTo(result);
+        result += adapter3.length();
+        adapter4.writeTo(result);
+        result += adapter4.length();
+        adapter5.writeTo(result);
+        result += adapter5.length();
+        adapter6.writeTo(result);
+        result += adapter6.length();
+        adapter7.writeTo(result);
+        result += adapter7.length();
+        adapter8.writeTo(result);
+
+        return resultImpl.release();
+    }
+
+    UChar* buffer;
     RefPtr<StringImpl> resultImpl = StringImpl::tryCreateUninitialized(length, buffer);
     if (!resultImpl)
         return 0;
@@ -561,7 +808,6 @@
     StringTypeAdapter<StringType8> adapter8(string8);
     StringTypeAdapter<StringType9> adapter9(string9);
 
-    UChar* buffer;
     bool overflow = false;
     unsigned length = adapter1.length();
     sumWithOverflow(length, adapter2.length(), overflow);
@@ -574,6 +820,36 @@
     sumWithOverflow(length, adapter9.length(), overflow);
     if (overflow)
         return 0;
+
+    if (adapter1.is8Bit() && adapter2.is8Bit() && adapter3.is8Bit() && adapter4.is8Bit() && adapter5.is8Bit() && adapter6.is8Bit() && adapter7.is8Bit() && adapter8.is8Bit() && adapter9.is8Bit()) {
+        LChar* buffer;
+        RefPtr<StringImpl> resultImpl = StringImpl::tryCreateUninitialized(length, buffer);
+        if (!resultImpl)
+            return 0;
+
+        LChar* result = buffer;
+        adapter1.writeTo(result);
+        result += adapter1.length();
+        adapter2.writeTo(result);
+        result += adapter2.length();
+        adapter3.writeTo(result);
+        result += adapter3.length();
+        adapter4.writeTo(result);
+        result += adapter4.length();
+        adapter5.writeTo(result);
+        result += adapter5.length();
+        adapter6.writeTo(result);
+        result += adapter6.length();
+        adapter7.writeTo(result);
+        result += adapter7.length();
+        adapter8.writeTo(result);
+        result += adapter8.length();
+        adapter9.writeTo(result);
+
+        return resultImpl.release();
+    }
+
+    UChar* buffer;
     RefPtr<StringImpl> resultImpl = StringImpl::tryCreateUninitialized(length, buffer);
     if (!resultImpl)
         return 0;

Modified: trunk/Source/_javascript_Core/wtf/text/StringOperators.h (102379 => 102380)


--- trunk/Source/_javascript_Core/wtf/text/StringOperators.h	2011-12-08 21:29:31 UTC (rev 102379)
+++ trunk/Source/_javascript_Core/wtf/text/StringOperators.h	2011-12-08 21:47:42 UTC (rev 102380)
@@ -46,6 +46,22 @@
         return operator String();
     }
 
+    bool is8Bit()
+    {
+        StringTypeAdapter<StringType1> adapter1(m_string1);
+        StringTypeAdapter<StringType2> adapter2(m_string2);
+        return adapter1.is8Bit() && adapter2.is8Bit();
+    }
+
+    void writeTo(LChar* destination)
+    {
+        ASSERT(is8Bit());
+        StringTypeAdapter<StringType1> adapter1(m_string1);
+        StringTypeAdapter<StringType2> adapter2(m_string2);
+        adapter1.writeTo(destination);
+        adapter2.writeTo(destination + adapter1.length());
+    }
+
     void writeTo(UChar* destination)
     {
         StringTypeAdapter<StringType1> adapter1(m_string1);
@@ -75,6 +91,10 @@
     }
 
     unsigned length() { return m_buffer.length(); }
+
+    bool is8Bit() { return m_buffer.is8Bit(); }
+
+    void writeTo(LChar* destination) { m_buffer.writeTo(destination); }
     void writeTo(UChar* destination) { m_buffer.writeTo(destination); }
 
 private:
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
http://lists.webkit.org/mailman/listinfo.cgi/webkit-changes

Reply via email to