[Bf-blender-cvs] [ecd2e2b4543] functions: move shared without incref and decref

Jacques Lucke noreply at git.blender.org
Sun Feb 10 20:26:18 CET 2019


Commit: ecd2e2b45432219dc558b01a3c1a9cc00a9c0785
Author: Jacques Lucke
Date:   Thu Feb 7 13:51:27 2019 +0100
Branches: functions
https://developer.blender.org/rBecd2e2b45432219dc558b01a3c1a9cc00a9c0785

move shared without incref and decref

===================================================================

M	source/blender/blenlib/BLI_shared.hpp

===================================================================

diff --git a/source/blender/blenlib/BLI_shared.hpp b/source/blender/blenlib/BLI_shared.hpp
index 60c599ab8ef..b2b69131262 100644
--- a/source/blender/blenlib/BLI_shared.hpp
+++ b/source/blender/blenlib/BLI_shared.hpp
@@ -79,15 +79,18 @@ namespace BLI {
 			this->incref();
 		}
 
-		Shared(const Shared &&other)
+		Shared(Shared &&other)
 		{
 			this->m_object = other.m_object;
-			this->incref();
+			other.m_object = nullptr;
 		}
 
 		~Shared()
 		{
-			this->decref();
+			/* Can be nullptr when previously moved. */
+			if (this->m_object != nullptr) {
+				this->decref();
+			}
 		}
 
 		Shared &operator=(const Shared &other)
@@ -102,11 +105,11 @@ namespace BLI {
 			return *this;
 		}
 
-		Shared &operator=(const Shared &&other)
+		Shared &operator=(Shared &&other)
 		{
 			this->decref();
 			this->m_object = other.m_object;
-			this->incref();
+			other.m_object = nullptr;
 			return *this;
 		}



More information about the Bf-blender-cvs mailing list