SGSharedPtr: optimized version of the free function swap()

With this simple change, the speedup as compared to commit 18f048424 is
now 37 % for the benchmark given in the previous commit. This is because
optimized swap() only needs to swap the raw pointers, which is certainly
less work than the three move assignments on SGSharedPtr (not raw
pointers) done by std::swap().

To benefit from this, write code like:

  using std::swap;  // now useless for SGSharedPtr, but idiomatic
  swap(ptr1, ptr2); // *not* std::swap()!
This commit is contained in:
Florent Rougon 2017-11-14 01:31:03 +01:00
parent a9ec3be2fd
commit 0c7cabe46f

View File

@ -134,6 +134,12 @@ private:
friend class SGWeakPtr;
};
template<class T>
void swap(SGSharedPtr<T>& a, SGSharedPtr<T>& b) noexcept
{
a.swap(b);
}
/**
* Support for boost::mem_fn
*/