Commit 372f7d24 authored by andersca@apple.com's avatar andersca@apple.com

String should be move enabled/optimized

https://bugs.webkit.org/show_bug.cgi?id=87596

Reviewed by Andreas Kling.

Add move constructors and move assignment operators to String and AtomicString when building with
compilers that support rvalue references. This gets rid of ref-churn when the source of the
constructor or assignment is a temporary object.

* wtf/text/AtomicString.h:
(AtomicString):
(WTF::AtomicString::AtomicString):
(WTF::AtomicString::operator=):
* wtf/text/WTFString.h:
(String):
(WTF::String::String):
(WTF::String::operator=):

git-svn-id: http://svn.webkit.org/repository/webkit/trunk@118859 268f45cc-cd09-0410-ab3c-d52691b4dbfc
parent 4c0875e8
2012-05-29 Anders Carlsson <andersca@apple.com>
String should be move enabled/optimized
https://bugs.webkit.org/show_bug.cgi?id=87596
Reviewed by Andreas Kling.
Add move constructors and move assignment operators to String and AtomicString when building with
compilers that support rvalue references. This gets rid of ref-churn when the source of the
constructor or assignment is a temporary object.
* wtf/text/AtomicString.h:
(AtomicString):
(WTF::AtomicString::AtomicString):
(WTF::AtomicString::operator=):
* wtf/text/WTFString.h:
(String):
(WTF::String::String):
(WTF::String::operator=):
2012-05-29 Alexandre Elias <aelias@google.com>
Support WebKit log messages on Android
......
......@@ -51,6 +51,17 @@ public:
ATOMICSTRING_CONVERSION AtomicString(const String& s) : m_string(add(s.impl())) { }
AtomicString(StringImpl* baseString, unsigned start, unsigned length) : m_string(add(baseString, start, length)) { }
#if COMPILER_SUPPORTS(CXX_RVALUE_REFERENCES)
// We have to declare the copy constructor and copy assignment operator as well, otherwise
// they'll be implicitly deleted by adding the move constructor and move assignment operator.
// FIXME: Instead of explicitly casting to String&& here, we should use std::move, but that requires us to
// have a standard library that supports move semantics.
AtomicString(const AtomicString& other) : m_string(other.m_string) { }
AtomicString(AtomicString&& other) : m_string(static_cast<String&&>(other.m_string)) { }
AtomicString& operator=(const AtomicString& other) { m_string = other.m_string; return *this; }
AtomicString& operator=(AtomicString&& other) { m_string = static_cast<String&&>(other.m_string); return *this; }
#endif
// Hash table deleted values, which are only constructed and never copied or destroyed.
AtomicString(WTF::HashTableDeletedValueType) : m_string(WTF::HashTableDeletedValue) { }
bool isHashTableDeletedValue() const { return m_string.isHashTableDeletedValue(); }
......
......@@ -131,6 +131,15 @@ public:
String(PassRefPtr<StringImpl> impl) : m_impl(impl) { }
String(RefPtr<StringImpl> impl) : m_impl(impl) { }
#if COMPILER_SUPPORTS(CXX_RVALUE_REFERENCES)
// We have to declare the copy constructor and copy assignment operator as well, otherwise
// they'll be implicitly deleted by adding the move constructor and move assignment operator.
String(const String& other) : m_impl(other.m_impl) { }
String(String&& other) : m_impl(other.m_impl.release()) { }
String& operator=(const String& other) { m_impl = other.m_impl; return *this; }
String& operator=(String&& other) { m_impl = other.m_impl.release(); return *this; }
#endif
// Inline the destructor.
ALWAYS_INLINE ~String() { }
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment