Commit a22ee114 authored by ch.dumez@samsung.com's avatar ch.dumez@samsung.com

Add move constructor and assignment operator to RefPtr class

Add move constructor and assignment operator to RefPtr class. As a result, we
can now use the implicitly defined move constructor and assignment operator for
Atomic String. Also, other classes with RefPtr data members like CString now
get a better default move constructor and assignment operator.

The release binary is ~21Kb smaller, there is no diff on the generated asm
for CString and AtomicString. However, there is a small diff for WTFString.o:
http://pastebin.com/RTzX23JV

The generated assembly for "CString WTF::String::latin1() const" and
"CString WTF::String::ascii() const" is slightly smaller, likely due to
CString's improved move copy constructor as these methods return CStrings.

Review URL: https://codereview.chromium.org/354023003

git-svn-id: svn://svn.chromium.org/blink/trunk@177066 bbb929c8-8fbe-4397-9dbb-9b2b20218538
parent 62cfb05f
...@@ -44,6 +44,11 @@ namespace WTF { ...@@ -44,6 +44,11 @@ namespace WTF {
ALWAYS_INLINE RefPtr(const RefPtr& o) : m_ptr(o.m_ptr) { refIfNotNull(m_ptr); } ALWAYS_INLINE RefPtr(const RefPtr& o) : m_ptr(o.m_ptr) { refIfNotNull(m_ptr); }
template<typename U> RefPtr(const RefPtr<U>& o, EnsurePtrConvertibleArgDecl(U, T)) : m_ptr(o.get()) { refIfNotNull(m_ptr); } template<typename U> RefPtr(const RefPtr<U>& o, EnsurePtrConvertibleArgDecl(U, T)) : m_ptr(o.get()) { refIfNotNull(m_ptr); }
#if COMPILER_SUPPORTS(CXX_RVALUE_REFERENCES)
RefPtr(RefPtr&& o) : m_ptr(o.m_ptr) { o.m_ptr = 0; }
RefPtr& operator=(RefPtr&&);
#endif
// See comments in PassRefPtr.h for an explanation of why this takes a const reference. // See comments in PassRefPtr.h for an explanation of why this takes a const reference.
template<typename U> RefPtr(const PassRefPtr<U>&, EnsurePtrConvertibleArgDecl(U, T)); template<typename U> RefPtr(const PassRefPtr<U>&, EnsurePtrConvertibleArgDecl(U, T));
...@@ -103,6 +108,14 @@ namespace WTF { ...@@ -103,6 +108,14 @@ namespace WTF {
return *this; return *this;
} }
#if COMPILER_SUPPORTS(CXX_RVALUE_REFERENCES)
template<typename T> inline RefPtr<T>& RefPtr<T>::operator=(RefPtr&& o)
{
swap(o);
return *this;
}
#endif
template<typename T> template<typename U> inline RefPtr<T>& RefPtr<T>::operator=(const RefPtr<U>& o) template<typename T> template<typename U> inline RefPtr<T>& RefPtr<T>::operator=(const RefPtr<U>& o)
{ {
RefPtr ptr = o; RefPtr ptr = o;
......
...@@ -69,17 +69,6 @@ public: ...@@ -69,17 +69,6 @@ public:
COMPILE_ASSERT((charactersCount - 1 <= ((unsigned(~0) - sizeof(StringImpl)) / sizeof(LChar))), AtomicStringFromLiteralCannotOverflow); COMPILE_ASSERT((charactersCount - 1 <= ((unsigned(~0) - sizeof(StringImpl)) / sizeof(LChar))), AtomicStringFromLiteralCannotOverflow);
} }
#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. // Hash table deleted values, which are only constructed and never copied or destroyed.
AtomicString(WTF::HashTableDeletedValueType) : m_string(WTF::HashTableDeletedValue) { } AtomicString(WTF::HashTableDeletedValueType) : m_string(WTF::HashTableDeletedValue) { }
bool isHashTableDeletedValue() const { return m_string.isHashTableDeletedValue(); } bool isHashTableDeletedValue() const { return m_string.isHashTableDeletedValue(); }
......
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