diff options
author | Chris Robinson <[email protected]> | 2019-09-20 10:58:29 -0700 |
---|---|---|
committer | Chris Robinson <[email protected]> | 2019-09-20 10:58:29 -0700 |
commit | b9daffe1590b12b103f9706dfb0a440b629f3c49 (patch) | |
tree | 518977382c07d82be18299748b68f18dde3b92c5 | |
parent | 057b253adba81430e51ce07951eda7dda03f7a08 (diff) |
Don't clean up more than necessary on destruction
-rw-r--r-- | common/aloptional.h | 4 | ||||
-rw-r--r-- | common/intrusive_ptr.h | 10 |
2 files changed, 10 insertions, 4 deletions
diff --git a/common/aloptional.h b/common/aloptional.h index 79827482..269cba0e 100644 --- a/common/aloptional.h +++ b/common/aloptional.h @@ -9,7 +9,7 @@ namespace al { -#define REQUIRES(...) bool _rt=true, typename std::enable_if<_rt && (__VA_ARGS__),int>::type = 0 +#define REQUIRES(...) bool rt_=true, typename std::enable_if<rt_ && (__VA_ARGS__),bool>::type = true struct nullopt_t { }; struct in_place_t { }; @@ -61,7 +61,7 @@ public: !std::is_constructible<U&&, T>::value)> constexpr optional(U&& value) : mHasValue{true}, mValue{std::forward<U>(value)} { } - ~optional() { reset(); } + ~optional() { if(mHasValue) al::destroy_at(std::addressof(mValue)); } optional& operator=(nullopt_t) noexcept { reset(); return *this; } template<REQUIRES(std::is_copy_constructible<T>::value && std::is_copy_assignable<T>::value)> diff --git a/common/intrusive_ptr.h b/common/intrusive_ptr.h index fa76ad48..595c831d 100644 --- a/common/intrusive_ptr.h +++ b/common/intrusive_ptr.h @@ -56,7 +56,7 @@ public: { rhs.mPtr = nullptr; } intrusive_ptr(std::nullptr_t) noexcept { } explicit intrusive_ptr(T *ptr) noexcept : mPtr{ptr} { } - ~intrusive_ptr() { reset(); } + ~intrusive_ptr() { if(mPtr) mPtr->release(); } intrusive_ptr& operator=(const intrusive_ptr &rhs) noexcept { @@ -66,7 +66,13 @@ public: return *this; } intrusive_ptr& operator=(intrusive_ptr&& rhs) noexcept - { std::swap(mPtr, rhs.mPtr); return *this; } + { + if(mPtr) + mPtr->release(); + mPtr = rhs.mPtr; + rhs.mPtr = nullptr; + return *this; + } operator bool() const noexcept { return mPtr != nullptr; } |