move input shared_ptr in atomic_shared_ptr constructor
authorIlya Maykov <ilyam@fb.com>
Fri, 23 Jun 2017 18:32:32 +0000 (11:32 -0700)
committerFacebook Github Bot <facebook-github-bot@users.noreply.github.com>
Fri, 23 Jun 2017 18:37:25 +0000 (11:37 -0700)
Summary: By moving the input shared_ptr instead of copying it, we avoid doing an unnecessary ref count increment + decrement.

Reviewed By: djwatson, yfeldblum

Differential Revision: D5298467

fbshipit-source-id: b9f0b6999278609417bb4dc062030ca2388ba20a

folly/experimental/AtomicSharedPtr.h

index 6e4ef54a36eab5f2649adab5e6fac68f29f27fa3..7e8dce051991730a29dc199fc2431500c7d0ab7d 100644 (file)
@@ -81,7 +81,7 @@ class atomic_shared_ptr {
   }
   explicit atomic_shared_ptr(SharedPtr foo) /* noexcept */
       : atomic_shared_ptr() {
-    store(foo);
+    store(std::move(foo));
   }
   atomic_shared_ptr(const atomic_shared_ptr<T>&) = delete;
 
@@ -89,7 +89,7 @@ class atomic_shared_ptr {
     store(SharedPtr(nullptr));
   }
   void operator=(SharedPtr desired) /* noexcept */ {
-    store(desired);
+    store(std::move(desired));
   }
   void operator=(const atomic_shared_ptr<T>&) = delete;