From 6f3e9d2c4ca64f280f0d6a105d0b254a9e86457c Mon Sep 17 00:00:00 2001 From: Max Kellermann Date: Tue, 25 Feb 2020 20:53:29 +0100 Subject: [PATCH] IntrusivePtr: optimize release() using std::exchange() --- src/IntrusivePtr.h | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/src/IntrusivePtr.h b/src/IntrusivePtr.h index 767aae197c..3af6fc6fc0 100644 --- a/src/IntrusivePtr.h +++ b/src/IntrusivePtr.h @@ -123,10 +123,7 @@ public: */ pointer release() noexcept { - auto result = ptr_; - if ( result ) - ptr_ = nullptr; - return result; + return std::exchange(ptr_, nullptr); } IntrusivePtr& operator=(IntrusivePtr other) noexcept