Stop using SkTSwap.

Use std::swap instead. It does not appear that any external user
specializes SkTSwap, but some may still use it. This removes all use in
Skia so that SkTSwap can later be removed in a smaller CL. After that
the <utility> include can be removed from SkTypes.h.

Change-Id: If03d4ee07dbecda961aa9f0dc34d171ef5168753
Reviewed-on: https://skia-review.googlesource.com/135578
Reviewed-by: Hal Canary <halcanary@google.com>
Reviewed-by: Mike Klein <mtklein@google.com>
Commit-Queue: Ben Wagner <bungeman@google.com>
diff --git a/include/core/SkRect.h b/include/core/SkRect.h
index b33b0b9..ed0e599 100644
--- a/include/core/SkRect.h
+++ b/include/core/SkRect.h
@@ -23,6 +23,8 @@
 #include "../private/SkSafe32.h"
 #include "../private/SkTFitsIn.h"
 
+#include <utility>
+
 struct SkRect;
 
 /** \struct SkIRect
@@ -646,11 +648,12 @@
         and width() and height() will be zero or positive.
     */
     void sort() {
+        using std::swap;
         if (fLeft > fRight) {
-            SkTSwap<int32_t>(fLeft, fRight);
+            swap(fLeft, fRight);
         }
         if (fTop > fBottom) {
-            SkTSwap<int32_t>(fTop, fBottom);
+            swap(fTop, fBottom);
         }
     }
 
@@ -1519,12 +1522,13 @@
         and width() and height() will be zero or positive.
     */
     void sort() {
+        using std::swap;
         if (fLeft > fRight) {
-            SkTSwap<SkScalar>(fLeft, fRight);
+            swap(fLeft, fRight);
         }
 
         if (fTop > fBottom) {
-            SkTSwap<SkScalar>(fTop, fBottom);
+            swap(fTop, fBottom);
         }
     }
 
diff --git a/include/core/SkString.h b/include/core/SkString.h
index aa3292a..300d9ed 100644
--- a/include/core/SkString.h
+++ b/include/core/SkString.h
@@ -274,9 +274,7 @@
 /// optional.
 static inline SkString SkStringPrintf() { return SkString(); }
 
-// Specialized to take advantage of SkString's fast swap path. The unspecialized function is
-// declared in SkTypes.h and called by SkTSort.
-template <> inline void SkTSwap(SkString& a, SkString& b) {
+static inline void swap(SkString& a, SkString& b) {
     a.swap(b);
 }
 
diff --git a/include/gpu/gl/GrGLExtensions.h b/include/gpu/gl/GrGLExtensions.h
index 0b1ff44..73e5097 100644
--- a/include/gpu/gl/GrGLExtensions.h
+++ b/include/gpu/gl/GrGLExtensions.h
@@ -12,6 +12,8 @@
 #include "GrGLFunctions.h"
 #include "SkString.h"
 
+#include <utility>
+
 struct GrGLInterface;
 class SkJSONWriter;
 
@@ -30,8 +32,9 @@
     GrGLExtensions& operator=(const GrGLExtensions&);
 
     void swap(GrGLExtensions* that) {
-        fStrings.swap(&that->fStrings);
-        SkTSwap(fInitialized, that->fInitialized);
+        using std::swap;
+        swap(fStrings, that->fStrings);
+        swap(fInitialized, that->fInitialized);
     }
 
     /**
diff --git a/include/private/SkMessageBus.h b/include/private/SkMessageBus.h
index 6ddf82c..19e9375 100644
--- a/include/private/SkMessageBus.h
+++ b/include/private/SkMessageBus.h
@@ -93,7 +93,7 @@
     SkASSERT(messages);
     messages->reset();
     SkAutoMutexAcquire lock(fMessagesMutex);
-    fMessages.swap(messages);
+    fMessages.swap(*messages);
 }
 
 //   ----------------------- Implementation of SkMessageBus -----------------------
diff --git a/include/private/SkTArray.h b/include/private/SkTArray.h
index c9bee99..75cd001 100644
--- a/include/private/SkTArray.h
+++ b/include/private/SkTArray.h
@@ -298,18 +298,19 @@
 
     /** Swaps the contents of this array with that array. Does a pointer swap if possible,
         otherwise copies the T values. */
-    void swap(SkTArray* that) {
-        if (this == that) {
+    void swap(SkTArray& that) {
+        using std::swap;
+        if (this == &that) {
             return;
         }
-        if (fOwnMemory && that->fOwnMemory) {
-            SkTSwap(fItemArray, that->fItemArray);
-            SkTSwap(fCount, that->fCount);
-            SkTSwap(fAllocCount, that->fAllocCount);
+        if (fOwnMemory && that.fOwnMemory) {
+            swap(fItemArray, that.fItemArray);
+            swap(fCount, that.fCount);
+            swap(fAllocCount, that.fAllocCount);
         } else {
             // This could be more optimal...
-            SkTArray copy(std::move(*that));
-            *that = std::move(*this);
+            SkTArray copy(std::move(that));
+            that = std::move(*this);
             *this = std::move(copy);
         }
     }
@@ -563,6 +564,10 @@
     bool fReserved : 1;
 };
 
+template <typename T, bool M> static inline void swap(SkTArray<T, M>& a, SkTArray<T, M>& b) {
+    a.swap(b);
+}
+
 template<typename T, bool MEM_MOVE> constexpr int SkTArray<T, MEM_MOVE>::kMinHeapAllocCount;
 
 /**
diff --git a/include/private/SkTDArray.h b/include/private/SkTDArray.h
index dd3212d..c6bd4ff 100644
--- a/include/private/SkTDArray.h
+++ b/include/private/SkTDArray.h
@@ -13,6 +13,8 @@
 #include "SkTo.h"
 #include "SkTypes.h"
 
+#include <utility>
+
 template <typename T> class SkTDArray {
 public:
     SkTDArray() : fArray(nullptr), fReserve(0), fCount(0) {}
@@ -67,10 +69,11 @@
         return !(a == b);
     }
 
-    void swap(SkTDArray<T>& other) {
-        SkTSwap(fArray, other.fArray);
-        SkTSwap(fReserve, other.fReserve);
-        SkTSwap(fCount, other.fCount);
+    void swap(SkTDArray<T>& that) {
+        using std::swap;
+        swap(fArray, that.fArray);
+        swap(fReserve, that.fReserve);
+        swap(fCount, that.fCount);
     }
 
     bool isEmpty() const { return fCount == 0; }
@@ -371,4 +374,8 @@
     }
 };
 
+template <typename T> static inline void swap(SkTDArray<T>& a, SkTDArray<T>& b) {
+    a.swap(b);
+}
+
 #endif