Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(15)

Side by Side Diff: Source/wtf/RefPtr.h

Issue 354023003: Add move constructor and assignment operator to RefPtr class (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Take Nico's feedback into consideration Created 6 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | Source/wtf/text/AtomicString.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2005, 2006, 2007, 2008, 2009, 2010, 2013 Apple Inc. All rights reserved. 2 * Copyright (C) 2005, 2006, 2007, 2008, 2009, 2010, 2013 Apple Inc. All rights reserved.
3 * 3 *
4 * This library is free software; you can redistribute it and/or 4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Library General Public 5 * modify it under the terms of the GNU Library General Public
6 * License as published by the Free Software Foundation; either 6 * License as published by the Free Software Foundation; either
7 * version 2 of the License, or (at your option) any later version. 7 * version 2 of the License, or (at your option) any later version.
8 * 8 *
9 * This library is distributed in the hope that it will be useful, 9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
(...skipping 26 matching lines...) Expand all
37 WTF_DISALLOW_ZERO_ASSIGNMENT(RefPtr); 37 WTF_DISALLOW_ZERO_ASSIGNMENT(RefPtr);
38 public: 38 public:
39 ALWAYS_INLINE RefPtr() : m_ptr(0) { } 39 ALWAYS_INLINE RefPtr() : m_ptr(0) { }
40 ALWAYS_INLINE RefPtr(std::nullptr_t) : m_ptr(0) { } 40 ALWAYS_INLINE RefPtr(std::nullptr_t) : m_ptr(0) { }
41 ALWAYS_INLINE RefPtr(T* ptr) : m_ptr(ptr) { refIfNotNull(ptr); } 41 ALWAYS_INLINE RefPtr(T* ptr) : m_ptr(ptr) { refIfNotNull(ptr); }
42 template<typename U> RefPtr(const RawPtr<U>& ptr, EnsurePtrConvertibleAr gDecl(U, T)) : m_ptr(ptr.get()) { refIfNotNull(m_ptr); } 42 template<typename U> RefPtr(const RawPtr<U>& ptr, EnsurePtrConvertibleAr gDecl(U, T)) : m_ptr(ptr.get()) { refIfNotNull(m_ptr); }
43 ALWAYS_INLINE explicit RefPtr(T& ref) : m_ptr(&ref) { m_ptr->ref(); } 43 ALWAYS_INLINE explicit RefPtr(T& ref) : m_ptr(&ref) { m_ptr->ref(); }
44 ALWAYS_INLINE RefPtr(const RefPtr& o) : m_ptr(o.m_ptr) { refIfNotNull(m_ ptr); } 44 ALWAYS_INLINE RefPtr(const RefPtr& o) : m_ptr(o.m_ptr) { refIfNotNull(m_ ptr); }
45 template<typename U> RefPtr(const RefPtr<U>& o, EnsurePtrConvertibleArgD ecl(U, T)) : m_ptr(o.get()) { refIfNotNull(m_ptr); } 45 template<typename U> RefPtr(const RefPtr<U>& o, EnsurePtrConvertibleArgD ecl(U, T)) : m_ptr(o.get()) { refIfNotNull(m_ptr); }
46 46
47 #if COMPILER_SUPPORTS(CXX_RVALUE_REFERENCES)
48 RefPtr(RefPtr&& o) : m_ptr(o.m_ptr) { o.m_ptr = 0; }
49 RefPtr& operator=(RefPtr&&);
50 #endif
51
47 // See comments in PassRefPtr.h for an explanation of why this takes a c onst reference. 52 // See comments in PassRefPtr.h for an explanation of why this takes a c onst reference.
48 template<typename U> RefPtr(const PassRefPtr<U>&, EnsurePtrConvertibleAr gDecl(U, T)); 53 template<typename U> RefPtr(const PassRefPtr<U>&, EnsurePtrConvertibleAr gDecl(U, T));
49 54
50 // Hash table deleted values, which are only constructed and never copie d or destroyed. 55 // Hash table deleted values, which are only constructed and never copie d or destroyed.
51 RefPtr(HashTableDeletedValueType) : m_ptr(hashTableDeletedValue()) { } 56 RefPtr(HashTableDeletedValueType) : m_ptr(hashTableDeletedValue()) { }
52 bool isHashTableDeletedValue() const { return m_ptr == hashTableDeletedV alue(); } 57 bool isHashTableDeletedValue() const { return m_ptr == hashTableDeletedV alue(); }
53 58
54 ALWAYS_INLINE ~RefPtr() { derefIfNotNull(m_ptr); } 59 ALWAYS_INLINE ~RefPtr() { derefIfNotNull(m_ptr); }
55 60
56 ALWAYS_INLINE T* get() const { return m_ptr; } 61 ALWAYS_INLINE T* get() const { return m_ptr; }
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
96 derefIfNotNull(ptr); 101 derefIfNotNull(ptr);
97 } 102 }
98 103
99 template<typename T> inline RefPtr<T>& RefPtr<T>::operator=(const RefPtr& o) 104 template<typename T> inline RefPtr<T>& RefPtr<T>::operator=(const RefPtr& o)
100 { 105 {
101 RefPtr ptr = o; 106 RefPtr ptr = o;
102 swap(ptr); 107 swap(ptr);
103 return *this; 108 return *this;
104 } 109 }
105 110
111 #if COMPILER_SUPPORTS(CXX_RVALUE_REFERENCES)
112 template<typename T> inline RefPtr<T>& RefPtr<T>::operator=(RefPtr&& o)
113 {
114 swap(o);
Mikhail 2014/06/27 07:48:44 This does not look correct, look { RefPtr<A> a = a
115 return *this;
116 }
117 #endif
118
106 template<typename T> template<typename U> inline RefPtr<T>& RefPtr<T>::opera tor=(const RefPtr<U>& o) 119 template<typename T> template<typename U> inline RefPtr<T>& RefPtr<T>::opera tor=(const RefPtr<U>& o)
107 { 120 {
108 RefPtr ptr = o; 121 RefPtr ptr = o;
109 swap(ptr); 122 swap(ptr);
110 return *this; 123 return *this;
111 } 124 }
112 125
113 template<typename T> inline RefPtr<T>& RefPtr<T>::operator=(T* optr) 126 template<typename T> inline RefPtr<T>& RefPtr<T>::operator=(T* optr)
114 { 127 {
115 RefPtr ptr = optr; 128 RefPtr ptr = optr;
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after
199 private: 212 private:
200 T* m_ptr; 213 T* m_ptr;
201 }; 214 };
202 215
203 } // namespace WTF 216 } // namespace WTF
204 217
205 using WTF::RefPtr; 218 using WTF::RefPtr;
206 using WTF::static_pointer_cast; 219 using WTF::static_pointer_cast;
207 220
208 #endif // WTF_RefPtr_h 221 #endif // WTF_RefPtr_h
OLDNEW
« no previous file with comments | « no previous file | Source/wtf/text/AtomicString.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698