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

Unified Diff: base/memory/ref_counted.h

Issue 2961413003: Outline RefCountedThreadSafeBase::AddRef and Release on non-X86 (Closed)
Patch Set: Created 3 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | base/memory/ref_counted.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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;
« no previous file with comments | « no previous file | base/memory/ref_counted.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698