Title: [138194] trunk/Source/WTF
Revision
138194
Author
[email protected]
Date
2012-12-19 13:59:25 -0800 (Wed, 19 Dec 2012)

Log Message

StringImpl isolatedCopy unnecessarily copies text-segment character data
https://bugs.webkit.org/show_bug.cgi?id=105376

Reviewed by Anders Carlsson.

This patch adds a new (private) helper to StringImpl that tests whether the StringImpl
is backed by an ASCII literal.  This allows isolatedCopy() to safely use the createFromLiteral
constructor rather than making an unnecessary copy.

* wtf/text/StringImpl.h:
(StringImpl):
(WTF::StringImpl::isASCIILiteral):
(WTF::StringImpl::isolatedCopy):

Modified Paths

Diff

Modified: trunk/Source/WTF/ChangeLog (138193 => 138194)


--- trunk/Source/WTF/ChangeLog	2012-12-19 21:32:15 UTC (rev 138193)
+++ trunk/Source/WTF/ChangeLog	2012-12-19 21:59:25 UTC (rev 138194)
@@ -1,5 +1,21 @@
 2012-12-19  Oliver Hunt  <[email protected]>
 
+        StringImpl isolatedCopy unnecessarily copies text-segment character data
+        https://bugs.webkit.org/show_bug.cgi?id=105376
+
+        Reviewed by Anders Carlsson.
+
+        This patch adds a new (private) helper to StringImpl that tests whether the StringImpl
+        is backed by an ASCII literal.  This allows isolatedCopy() to safely use the createFromLiteral
+        constructor rather than making an unnecessary copy.
+
+        * wtf/text/StringImpl.h:
+        (StringImpl):
+        (WTF::StringImpl::isASCIILiteral):
+        (WTF::StringImpl::isolatedCopy):
+
+2012-12-19  Oliver Hunt  <[email protected]>
+
         WTF String from ASCIILiteral fails to correctly handle empty strings.
         https://bugs.webkit.org/show_bug.cgi?id=105453
 

Modified: trunk/Source/WTF/wtf/text/StringImpl.h (138193 => 138194)


--- trunk/Source/WTF/wtf/text/StringImpl.h	2012-12-19 21:32:15 UTC (rev 138193)
+++ trunk/Source/WTF/wtf/text/StringImpl.h	2012-12-19 21:59:25 UTC (rev 138194)
@@ -729,6 +729,12 @@
 #endif
 
 private:
+
+    bool isASCIILiteral() const
+    {
+        return is8Bit() && hasInternalBuffer() && reinterpret_cast<const void*>(m_data8) != reinterpret_cast<const void*>(this + 1);
+    }
+
     // This number must be at least 2 to avoid sharing empty, null as well as 1 character strings from SmallStrings.
     static const unsigned s_copyCharsInlineCutOff = 20;
 
@@ -1126,6 +1132,8 @@
 
 inline PassRefPtr<StringImpl> StringImpl::isolatedCopy() const
 {
+    if (isASCIILiteral())
+        return StringImpl::createFromLiteral(reinterpret_cast<const char*>(m_data8), m_length);
     if (is8Bit())
         return create(m_data8, m_length);
     return create(m_data16, m_length);
_______________________________________________
webkit-changes mailing list
[email protected]
http://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to