Title: [149372] trunk/Source/WTF
Revision
149372
Author
[email protected]
Date
2013-04-30 09:31:22 -0700 (Tue, 30 Apr 2013)

Log Message

String::isolatedCopy() can avoid a copy if the original is a temporary
https://bugs.webkit.org/show_bug.cgi?id=115425

Reviewed by Darin Adler.

* wtf/Compiler.h:
Add WTF_COMPILER_SUPPORTS_CXX_REFERENCE_QUALIFIED_FUNCTIONS define.

* wtf/text/WTFString.cpp:
(WTF::String::isolatedCopy):
* wtf/text/WTFString.h:
If COMPILER_SUPPORTS(CXX_REFERENCE_QUALIFIED_FUNCTIONS) is true, add two overloads of String::isolatedCopy().
One is used if *this is an lvalue, and one is used if *this is an rvalue. In the latter case, we know that the original
String object is a temporary and will be going away, so if it's safe to send it to another thread (if it's not an AtomicString,
and if it's refcount is 1), then we can just steal the StringImpl from the original and avoid a copy altogether.

Modified Paths

Diff

Modified: trunk/Source/WTF/ChangeLog (149371 => 149372)


--- trunk/Source/WTF/ChangeLog	2013-04-30 15:58:41 UTC (rev 149371)
+++ trunk/Source/WTF/ChangeLog	2013-04-30 16:31:22 UTC (rev 149372)
@@ -1,3 +1,21 @@
+2013-04-30  Anders Carlsson  <[email protected]>
+
+        String::isolatedCopy() can avoid a copy if the original is a temporary
+        https://bugs.webkit.org/show_bug.cgi?id=115425
+
+        Reviewed by Darin Adler.
+
+        * wtf/Compiler.h:
+        Add WTF_COMPILER_SUPPORTS_CXX_REFERENCE_QUALIFIED_FUNCTIONS define.
+
+        * wtf/text/WTFString.cpp:
+        (WTF::String::isolatedCopy):
+        * wtf/text/WTFString.h:
+        If COMPILER_SUPPORTS(CXX_REFERENCE_QUALIFIED_FUNCTIONS) is true, add two overloads of String::isolatedCopy().
+        One is used if *this is an lvalue, and one is used if *this is an rvalue. In the latter case, we know that the original
+        String object is a temporary and will be going away, so if it's safe to send it to another thread (if it's not an AtomicString,
+        and if it's refcount is 1), then we can just steal the StringImpl from the original and avoid a copy altogether.
+
 2013-04-30  Zalan Bujtas  <[email protected]>
 
         Animations fail to start on http://www.google.com/insidesearch/howsearchworks/thestory/

Modified: trunk/Source/WTF/wtf/Compiler.h (149371 => 149372)


--- trunk/Source/WTF/wtf/Compiler.h	2013-04-30 15:58:41 UTC (rev 149371)
+++ trunk/Source/WTF/wtf/Compiler.h	2013-04-30 16:31:22 UTC (rev 149372)
@@ -64,6 +64,7 @@
 #define WTF_COMPILER_SUPPORTS_CXX_OVERRIDE_CONTROL __has_extension(cxx_override_control)
 #define WTF_COMPILER_SUPPORTS_HAS_TRIVIAL_DESTRUCTOR __has_extension(has_trivial_destructor)
 #define WTF_COMPILER_SUPPORTS_CXX_STRONG_ENUMS __has_extension(cxx_strong_enums)
+#define WTF_COMPILER_SUPPORTS_CXX_REFERENCE_QUALIFIED_FUNCTIONS __has_extension(cxx_reference_qualified_functions)
 
 #endif
 

Modified: trunk/Source/WTF/wtf/text/WTFString.cpp (149371 => 149372)


--- trunk/Source/WTF/wtf/text/WTFString.cpp	2013-04-30 15:58:41 UTC (rev 149371)
+++ trunk/Source/WTF/wtf/text/WTFString.cpp	2013-04-30 16:31:22 UTC (rev 149372)
@@ -654,12 +654,35 @@
     return m_impl->toFloat(ok);
 }
 
+#if COMPILER_SUPPORTS(CXX_REFERENCE_QUALIFIED_FUNCTIONS)
+String String::isolatedCopy() const &
+{
+    if (!m_impl)
+        return String();
+    return m_impl->isolatedCopy();
+}
+
+String String::isolatedCopy() const &&
+{
+    if (isSafeToSendToAnotherThread()) {
+        // Since we know that our string is a temporary that will be destroyed
+        // we can just steal the m_impl from it, thus avoiding a copy.
+        return String(std::move(*this));
+    }
+
+    if (!m_impl)
+        return String();
+
+    return m_impl->isolatedCopy();
+}
+#else
 String String::isolatedCopy() const
 {
     if (!m_impl)
         return String();
     return m_impl->isolatedCopy();
 }
+#endif
 
 bool String::isSafeToSendToAnotherThread() const
 {

Modified: trunk/Source/WTF/wtf/text/WTFString.h (149371 => 149372)


--- trunk/Source/WTF/wtf/text/WTFString.h	2013-04-30 15:58:41 UTC (rev 149371)
+++ trunk/Source/WTF/wtf/text/WTFString.h	2013-04-30 16:31:22 UTC (rev 149372)
@@ -398,7 +398,13 @@
 
     bool percentage(int& percentage) const;
 
+#if COMPILER_SUPPORTS(CXX_REFERENCE_QUALIFIED_FUNCTIONS)
+    WTF_EXPORT_STRING_API String isolatedCopy() const &;
+    WTF_EXPORT_STRING_API String isolatedCopy() const &&;
+#else
     WTF_EXPORT_STRING_API String isolatedCopy() const;
+#endif
+
     WTF_EXPORT_STRING_API bool isSafeToSendToAnotherThread() const;
 
     // Prevent Strings from being implicitly convertable to bool as it will be ambiguous on any platform that
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to