Chromium Code Reviews| Index: base/memory/ref_counted.h |
| diff --git a/base/memory/ref_counted.h b/base/memory/ref_counted.h |
| index 743dbabd541fca6fdadcf02a30284cef12bcb999..ae9b6f0187817e7c9ed72903b59fd030449885ba 100644 |
| --- a/base/memory/ref_counted.h |
| +++ b/base/memory/ref_counted.h |
| @@ -142,7 +142,31 @@ class BASE_EXPORT RefCountedThreadSafeBase { |
| ~RefCountedThreadSafeBase(); |
| - void AddRef() const { |
| +// Release and AddRef are suitable for inlining on X86 because they generate |
| +// very small code sequences. On other platforms (ARM), it causes a size |
| +// regression and is probably not worth it. |
| +#if defined(ARCH_CPU_X86_FAMILY) |
| + // Returns true if the object should self-delete. |
| + bool Release() const { return ReleaseImpl(); } |
| + void AddRef() const { AddRefImpl(); } |
| +#else |
| + // Returns true if the object should self-delete. |
| + bool Release() const; |
| + void AddRef() const; |
| +#endif |
| + |
| + private: |
| + template <typename U> |
| + friend scoped_refptr<U> base::AdoptRef(U*); |
| + |
| + void Adopted() const { |
| +#if DCHECK_IS_ON() |
| + DCHECK(needs_adopt_ref_); |
| + needs_adopt_ref_ = false; |
| +#endif |
| + } |
| + |
| + ALWAYS_INLINE void AddRefImpl() const { |
| #if DCHECK_IS_ON() |
| DCHECK(!in_dtor_); |
| DCHECK(!needs_adopt_ref_) |
| @@ -153,8 +177,7 @@ class BASE_EXPORT RefCountedThreadSafeBase { |
| AtomicRefCountInc(&ref_count_); |
| } |
| - // Returns true if the object should self-delete. |
| - bool Release() const { |
| + ALWAYS_INLINE bool ReleaseImpl() const { |
|
(unused - use chromium)
2017/06/30 16:19:06
Is the ALWAYS_INLINE needed? Seems like the compil
hans
2017/06/30 16:21:13
It should.
But I think the macro also expresses o
|
| #if DCHECK_IS_ON() |
| DCHECK(!in_dtor_); |
| DCHECK(!AtomicRefCountIsZero(&ref_count_)); |
| @@ -168,17 +191,6 @@ class BASE_EXPORT RefCountedThreadSafeBase { |
| return false; |
| } |
| - private: |
| - template <typename U> |
| - friend scoped_refptr<U> base::AdoptRef(U*); |
| - |
| - void Adopted() const { |
| -#if DCHECK_IS_ON() |
| - DCHECK(needs_adopt_ref_); |
| - needs_adopt_ref_ = false; |
| -#endif |
| - } |
| - |
| mutable AtomicRefCount ref_count_{0}; |
| #if DCHECK_IS_ON() |
| mutable bool needs_adopt_ref_ = false; |