summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorMaxime Coste <frrrwww@gmail.com>2015-11-10 13:50:15 +0000
committerMaxime Coste <frrrwww@gmail.com>2015-11-10 13:50:15 +0000
commit53184829ee32708487fb6a3028f822bc3fb28e33 (patch)
tree4417776d9c3b5f4f8ba94dc3bb5b35ddd612d983 /src
parent95c1d25f28cc7c04aa1abf93ccfc03165d340ab4 (diff)
Avoid unneeded inc/dec rec in RefPtr::operator=
Diffstat (limited to 'src')
-rw-r--r--src/ref_ptr.hh19
1 files changed, 13 insertions, 6 deletions
diff --git a/src/ref_ptr.hh b/src/ref_ptr.hh
index 33a56135..b001c14a 100644
--- a/src/ref_ptr.hh
+++ b/src/ref_ptr.hh
@@ -24,11 +24,15 @@ struct RefPtr
RefPtr& operator=(const RefPtr& other)
{
- release();
- m_ptr = other.m_ptr;
- acquire();
+ if (other.m_ptr != m_ptr)
+ {
+ release();
+ m_ptr = other.m_ptr;
+ acquire();
+ }
return *this;
}
+
RefPtr& operator=(RefPtr&& other)
{
release();
@@ -40,9 +44,12 @@ struct RefPtr
RefPtr& operator=(T* ptr)
{
- release();
- m_ptr = ptr;
- acquire();
+ if (ptr != m_ptr)
+ {
+ release();
+ m_ptr = ptr;
+ acquire();
+ }
return *this;
}