From ec24b2e338de2a6211723f19f54386c950ac5010 Mon Sep 17 00:00:00 2001 From: Dan Sinclair Date: Tue, 2 Jan 2018 12:13:05 -0500 Subject: Make SharedCopyOnWrite use Retainables This CL removes the CountedObject from SharedCopyOnWrite and instead converts the items being shared into Retainable subclasses. BUG: chromium:792372 Change-Id: I9570a521f2fc2434013c3ccb103273bdd2440bb8 Reviewed-on: https://pdfium-review.googlesource.com/22010 Reviewed-by: Tom Sepez Commit-Queue: dsinclair --- core/fxcrt/shared_copy_on_write.h | 32 +++----------------------------- 1 file changed, 3 insertions(+), 29 deletions(-) (limited to 'core/fxcrt/shared_copy_on_write.h') diff --git a/core/fxcrt/shared_copy_on_write.h b/core/fxcrt/shared_copy_on_write.h index c04730d5e0..f7d7a2afdb 100644 --- a/core/fxcrt/shared_copy_on_write.h +++ b/core/fxcrt/shared_copy_on_write.h @@ -24,7 +24,7 @@ class SharedCopyOnWrite { template ObjClass* Emplace(Args... params) { - m_pObject.Reset(new CountedObj(params...)); + m_pObject.Reset(new ObjClass(params...)); return m_pObject.Get(); } @@ -42,7 +42,7 @@ class SharedCopyOnWrite { if (!m_pObject) return Emplace(params...); if (!m_pObject->HasOneRef()) - m_pObject.Reset(new CountedObj(*m_pObject)); + m_pObject.Reset(new ObjClass(*m_pObject)); return m_pObject.Get(); } @@ -55,33 +55,7 @@ class SharedCopyOnWrite { explicit operator bool() const { return !!m_pObject; } private: - class CountedObj : public ObjClass { - public: - template - // NOLINTNEXTLINE(runtime/explicit) - CountedObj(Args... params) : ObjClass(params...), m_RefCount(0) {} - - CountedObj(const CountedObj& src) : ObjClass(src), m_RefCount(0) {} - ~CountedObj() { m_RefCount = 0; } - - bool HasOneRef() const { return m_RefCount == 1; } - void Retain() { m_RefCount++; } - void Release() { - ASSERT(m_RefCount); - if (--m_RefCount == 0) - delete this; - } - - private: - // To ensure ref counts do not overflow, consider the worst possible case: - // the entire address space contains nothing but pointers to this object. - // Since the count increments with each new pointer, the largest value is - // the number of pointers that can fit into the address space. The size of - // the address space itself is a good upper bound on it. - intptr_t m_RefCount; - }; - - RetainPtr m_pObject; + RetainPtr m_pObject; }; } // namespace fxcrt -- cgit v1.2.3