Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(324)

Side by Side Diff: src/core/SkTSort.h

Issue 2454763002: Move when swapping, if possible. (Closed)
Patch Set: Created 4 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « include/core/SkTypes.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright 2006 The Android Open Source Project 2 * Copyright 2006 The Android Open Source Project
3 * 3 *
4 * Use of this source code is governed by a BSD-style license that can be 4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file. 5 * found in the LICENSE file.
6 */ 6 */
7 7
8 8
9 #ifndef SkTSort_DEFINED 9 #ifndef SkTSort_DEFINED
10 #define SkTSort_DEFINED 10 #define SkTSort_DEFINED
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after
112 /** Sorts the array of size count using comparator '<' using a Heap Sort algorit hm. */ 112 /** Sorts the array of size count using comparator '<' using a Heap Sort algorit hm. */
113 template <typename T> void SkTHeapSort(T array[], size_t count) { 113 template <typename T> void SkTHeapSort(T array[], size_t count) {
114 SkTHeapSort(array, count, SkTCompareLT<T>()); 114 SkTHeapSort(array, count, SkTCompareLT<T>());
115 } 115 }
116 116
117 /////////////////////////////////////////////////////////////////////////////// 117 ///////////////////////////////////////////////////////////////////////////////
118 118
119 /** Sorts the array of size count using comparator lessThan using an Insertion S ort algorithm. */ 119 /** Sorts the array of size count using comparator lessThan using an Insertion S ort algorithm. */
120 template <typename T, typename C> static void SkTInsertionSort(T* left, T* right , C lessThan) { 120 template <typename T, typename C> static void SkTInsertionSort(T* left, T* right , C lessThan) {
121 for (T* next = left + 1; next <= right; ++next) { 121 for (T* next = left + 1; next <= right; ++next) {
122 T insert = *next; 122 T insert = std::move(*next);
123 T* hole = next; 123 T* hole = next;
124 while (left < hole && lessThan(insert, *(hole - 1))) { 124 while (left < hole && lessThan(insert, *(hole - 1))) {
125 *hole = *(hole - 1); 125 *hole = std::move(*(hole - 1));
126 --hole; 126 --hole;
127 } 127 }
128 *hole = insert; 128 *hole = std::move(insert);
129 } 129 }
130 } 130 }
131 131
132 /////////////////////////////////////////////////////////////////////////////// 132 ///////////////////////////////////////////////////////////////////////////////
133 133
134 template <typename T, typename C> 134 template <typename T, typename C>
135 static T* SkTQSort_Partition(T* left, T* right, T* pivot, C lessThan) { 135 static T* SkTQSort_Partition(T* left, T* right, T* pivot, C lessThan) {
136 T pivotValue = *pivot; 136 T pivotValue = *pivot;
137 SkTSwap(*pivot, *right); 137 SkTSwap(*pivot, *right);
138 T* newPivot = left; 138 T* newPivot = left;
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
200 template <typename T> void SkTQSort(T* left, T* right) { 200 template <typename T> void SkTQSort(T* left, T* right) {
201 SkTQSort(left, right, SkTCompareLT<T>()); 201 SkTQSort(left, right, SkTCompareLT<T>());
202 } 202 }
203 203
204 /** Sorts the region from left to right using comparator '* < *' using a Quick S ort algorithm. */ 204 /** Sorts the region from left to right using comparator '* < *' using a Quick S ort algorithm. */
205 template <typename T> void SkTQSort(T** left, T** right) { 205 template <typename T> void SkTQSort(T** left, T** right) {
206 SkTQSort(left, right, SkTPointerCompareLT<T>()); 206 SkTQSort(left, right, SkTPointerCompareLT<T>());
207 } 207 }
208 208
209 #endif 209 #endif
OLDNEW
« no previous file with comments | « include/core/SkTypes.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698