From 0c7cabe46f30272574638f840d6d50f61c566b63 Mon Sep 17 00:00:00 2001 From: Florent Rougon Date: Tue, 14 Nov 2017 01:31:03 +0100 Subject: [PATCH] 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()! --- simgear/structure/SGSharedPtr.hxx | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/simgear/structure/SGSharedPtr.hxx b/simgear/structure/SGSharedPtr.hxx index fdc64415..d9f5540d 100644 --- a/simgear/structure/SGSharedPtr.hxx +++ b/simgear/structure/SGSharedPtr.hxx @@ -134,6 +134,12 @@ private: friend class SGWeakPtr; }; +template +void swap(SGSharedPtr& a, SGSharedPtr& b) noexcept +{ + a.swap(b); +} + /** * Support for boost::mem_fn */