From 53184829ee32708487fb6a3028f822bc3fb28e33 Mon Sep 17 00:00:00 2001 From: Maxime Coste Date: Tue, 10 Nov 2015 13:50:15 +0000 Subject: [PATCH] Avoid unneeded inc/dec rec in RefPtr::operator= --- src/ref_ptr.hh | 19 +++++++++++++------ 1 file 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; }