From bbcd522052e59e2539e411919833a16fc125f3f9 Mon Sep 17 00:00:00 2001 From: "alexey.lysiuk" Date: Tue, 3 Aug 2021 09:52:30 +0300 Subject: [PATCH] - made RefCountedPtr follow rule of five --- src/common/utility/refcounted.h | 25 +++++++++++++++++++------ 1 file changed, 19 insertions(+), 6 deletions(-) diff --git a/src/common/utility/refcounted.h b/src/common/utility/refcounted.h index b0c87d9341..cff1770294 100644 --- a/src/common/utility/refcounted.h +++ b/src/common/utility/refcounted.h @@ -31,10 +31,20 @@ public: { if (ptr) ptr->IncRef(); } - + + RefCountedPtr(const RefCountedPtr& r) : ptr(r.ptr) + { + if (ptr) ptr->IncRef(); + } + + RefCountedPtr(RefCountedPtr&& r) : ptr(r.ptr) + { + r.ptr = nullptr; + } + RefCountedPtr & operator=(const RefCountedPtr& r) { - if (ptr != r.ptr) + if (this != &r) { if (ptr) ptr->DecRef(); ptr = r.ptr; @@ -54,11 +64,14 @@ public: return *this; } - RefCountedPtr & operator=(const RefCountedPtr&& r) + RefCountedPtr & operator=(RefCountedPtr&& r) { - if (ptr) ptr->DecRef(); - ptr = r.ptr; - r.ptr = nullptr; + if (this != &r) + { + if (ptr) ptr->DecRef(); + ptr = r.ptr; + r.ptr = nullptr; + } return *this; }