Index: base/memory/ref_counted.h |
diff --git a/base/memory/ref_counted.h b/base/memory/ref_counted.h |
index be4919c1a51908699c260936f4f6b3c62a98d9ab..9ca7451861328cdf48feebefd7041982f4bc0531 100644 |
--- a/base/memory/ref_counted.h |
+++ b/base/memory/ref_counted.h |
@@ -276,23 +276,23 @@ class scoped_refptr { |
scoped_refptr(T* p) : ptr_(p) { |
if (ptr_) |
- ptr_->AddRef(); |
+ AddRef(ptr_); |
} |
scoped_refptr(const scoped_refptr<T>& r) : ptr_(r.ptr_) { |
if (ptr_) |
- ptr_->AddRef(); |
+ AddRef(ptr_); |
} |
template <typename U> |
scoped_refptr(const scoped_refptr<U>& r) : ptr_(r.get()) { |
if (ptr_) |
- ptr_->AddRef(); |
+ AddRef(ptr_); |
} |
~scoped_refptr() { |
if (ptr_) |
- ptr_->Release(); |
+ Release(ptr_); |
} |
T* get() const { return ptr_; } |
@@ -316,11 +316,11 @@ class scoped_refptr { |
scoped_refptr<T>& operator=(T* p) { |
// AddRef first so that self assignment should work |
if (p) |
- p->AddRef(); |
+ AddRef(p); |
T* old_ptr = ptr_; |
ptr_ = p; |
if (old_ptr) |
- old_ptr->Release(); |
+ Release(old_ptr); |
return *this; |
} |
@@ -362,8 +362,26 @@ class scoped_refptr { |
protected: |
T* ptr_; |
+ |
+ private: |
+ // Non-inline helpers to allow: |
+ // class Opaque; |
+ // extern template class scoped_refptr<Opaque>; |
+ // Otherwise the compiler will complain that Opaque is an incomplete type. |
danakj
2014/10/09 00:06:57
Can you add a test that demonstrates this working?
mdempsky
2014/10/09 00:21:33
Sure. Do you know if there are any existing idiom
danakj
2014/10/09 00:31:47
That sounds like how I'd do it, putting the helper
mdempsky
2014/10/09 00:52:48
SGTM
|
+ static void AddRef(T* ptr); |
+ static void Release(T* ptr); |
}; |
+template <typename T> |
+void scoped_refptr<T>::AddRef(T* ptr) { |
+ ptr->AddRef(); |
danakj
2014/10/09 00:06:57
What does the code look like with/out this change
|
+} |
+ |
+template <typename T> |
+void scoped_refptr<T>::Release(T* ptr) { |
+ ptr->Release(); |
+} |
+ |
// Handy utility for creating a scoped_refptr<T> out of a T* explicitly without |
// having to retype all the template arguments |
template <typename T> |