[glibmm] RefPtr: move assignment operator: Use swap().



commit a427c8fb49a38912f8a7b6f1ffbf4aa9e2fb16d3
Author: Murray Cumming <murrayc murrayc com>
Date:   Tue Jul 28 10:31:10 2015 +0200

    RefPtr: move assignment operator: Use swap().
    
    This is not actually less efficient - the code is inline anyway.
    Bug #752876

 glib/glibmm/refptr.h |   12 +++---------
 1 files changed, 3 insertions(+), 9 deletions(-)
---
diff --git a/glib/glibmm/refptr.h b/glib/glibmm/refptr.h
index 4c1913e..5e21384 100644
--- a/glib/glibmm/refptr.h
+++ b/glib/glibmm/refptr.h
@@ -20,6 +20,7 @@
  */
 
 #include <glibmmconfig.h>
+#include <utility>
 
 namespace Glib
 {
@@ -323,17 +324,10 @@ RefPtr<T_CppObject>& RefPtr<T_CppObject>::operator=(const RefPtr& src)
 template <class T_CppObject> inline
 RefPtr<T_CppObject>& RefPtr<T_CppObject>::operator=(RefPtr&& src)
 {
-  if (pCppObject_)
-    pCppObject_->unreference();
-
-  pCppObject_ = src.pCppObject_;
+  RefPtr<T_CppObject> temp (std::move(src));
+  this->swap(temp);
   src.pCppObject_ = nullptr;
 
-  //This should work instead, but seems less efficient:
-  //RefPtr<T_CppObject> temp (src);
-  //this->swap(temp);
-  //src.pCppObject_ = nullptr;
-
   return *this;
 }
 



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]