diff options
Diffstat (limited to 'common/comptr.h')
-rw-r--r-- | common/comptr.h | 20 |
1 files changed, 10 insertions, 10 deletions
diff --git a/common/comptr.h b/common/comptr.h index ab9d4c53..5984ebd9 100644 --- a/common/comptr.h +++ b/common/comptr.h @@ -4,6 +4,8 @@ #include <cstddef> #include <utility> +#include "opthelpers.h" + template<typename T> class ComPtr { @@ -42,10 +44,13 @@ public: } ComPtr& operator=(ComPtr&& rhs) { - if(mPtr) - mPtr->Release(); - mPtr = rhs.mPtr; - rhs.mPtr = nullptr; + if(likely(&rhs != this)) + { + if(mPtr) + mPtr->Release(); + mPtr = rhs.mPtr; + rhs.mPtr = nullptr; + } return *this; } @@ -56,12 +61,7 @@ public: T* get() const noexcept { return mPtr; } T** getPtr() noexcept { return &mPtr; } - T* release() noexcept - { - T *ret{mPtr}; - mPtr = nullptr; - return ret; - } + T* release() noexcept { return std::exchange(mPtr, nullptr); } void swap(ComPtr &rhs) noexcept { std::swap(mPtr, rhs.mPtr); } void swap(ComPtr&& rhs) noexcept { std::swap(mPtr, rhs.mPtr); } |