Use the copy & swap trick to simplify some code in QSharedPointer
authorThiago Macieira <thiago.macieira@intel.com>
Wed, 23 May 2012 17:46:39 +0000 (19:46 +0200)
committerQt by Nokia <qt-info@nokia.com>
Tue, 12 Jun 2012 18:09:33 +0000 (20:09 +0200)
Change-Id: I5fa2fae19126bea60b9682ed7765681dd6da8c15
Reviewed-by: Lars Knoll <lars.knoll@nokia.com>
src/corelib/tools/qsharedpointer_impl.h

index 6dc5764..db4a058 100644 (file)
@@ -305,13 +305,14 @@ public:
     { if (d) ref(); }
     inline QSharedPointer<T> &operator=(const QSharedPointer<T> &other)
     {
-        internalCopy(other);
+        QSharedPointer copy(other);
+        swap(copy);
         return *this;
     }
 #ifdef Q_COMPILER_RVALUE_REFS
     inline QSharedPointer<T> &operator=(QSharedPointer<T> &&other)
     {
-        QSharedPointer<T>::internalSwap(other);
+        swap(other);
         return *this;
     }
 #endif
@@ -372,7 +373,7 @@ public:
     }
 #endif
 
-    inline void clear() { *this = QSharedPointer<T>(); }
+    inline void clear() { QSharedPointer copy; swap(copy); }
 
     QWeakPointer<T> toWeakRef() const;