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:
parent
a9ec3be2fd
commit
0c7cabe46f
@ -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
|
||||
*/
|
||||
|
Loading…
Reference in New Issue
Block a user