зеркало из https://github.com/mozilla/moz-skia.git
Just use std qsort
Review URL: https://codereview.appspot.com/6195052 git-svn-id: http://skia.googlecode.com/svn/trunk@3846 2bbb7eff-a529-9590-31e7-b0007b416f81
This commit is contained in:
Родитель
e3987da2d2
Коммит
c7a67cb57e
|
@ -167,10 +167,8 @@ private:
|
|||
char fStorage[STORAGE+1];
|
||||
};
|
||||
|
||||
extern "C" {
|
||||
typedef int (*SkQSortCompareProc)(const void*, const void*);
|
||||
void SkQSort(void* base, size_t count, size_t elemSize, SkQSortCompareProc);
|
||||
}
|
||||
// Helper when calling qsort with a compare proc that has typed its arguments
|
||||
#define SkCastForQSort(compare) reinterpret_cast<int (*)(const void*, const void*)>(compare)
|
||||
|
||||
#endif
|
||||
|
||||
|
|
|
@ -462,8 +462,7 @@ bool SkRegion::getBoundaryPath(SkPath* path) const {
|
|||
edge[0].set(r.fLeft, r.fBottom, r.fTop);
|
||||
edge[1].set(r.fRight, r.fTop, r.fBottom);
|
||||
}
|
||||
SkQSort(edges.begin(), edges.count(), sizeof(Edge),
|
||||
(SkQSortCompareProc)EdgeProc);
|
||||
qsort(edges.begin(), edges.count(), sizeof(Edge), SkCastForQSort(EdgeProc));
|
||||
|
||||
int count = edges.count();
|
||||
Edge* start = edges.begin();
|
||||
|
|
|
@ -113,67 +113,3 @@ SkAutoAsciiToLC::~SkAutoAsciiToLC()
|
|||
}
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#define SK_QSortTempSize 16
|
||||
|
||||
static inline void sk_qsort_swap(char a[], char b[], size_t elemSize)
|
||||
{
|
||||
char tmp[SK_QSortTempSize];
|
||||
|
||||
while (elemSize > 0)
|
||||
{
|
||||
size_t size = elemSize;
|
||||
if (size > SK_QSortTempSize)
|
||||
size = SK_QSortTempSize;
|
||||
elemSize -= size;
|
||||
|
||||
memcpy(tmp, a, size);
|
||||
memcpy(a, b, size);
|
||||
memcpy(b, tmp, size);
|
||||
a += size;
|
||||
b += size;
|
||||
}
|
||||
}
|
||||
|
||||
static void SkQSort_Partition(char* first, char* last, size_t elemSize, SkQSortCompareProc compare)
|
||||
{
|
||||
char* left = first;
|
||||
char* rite = last;
|
||||
char* pivot = left;
|
||||
|
||||
while (left <= rite)
|
||||
{
|
||||
while (left < last && compare(left, pivot) < 0)
|
||||
left += elemSize;
|
||||
while (first < rite && compare(rite, pivot) > 0)
|
||||
rite -= elemSize;
|
||||
if (left <= rite)
|
||||
{
|
||||
if (left < rite)
|
||||
{
|
||||
SkASSERT(compare(left, rite) >= 0);
|
||||
sk_qsort_swap(left, rite, elemSize);
|
||||
}
|
||||
left += elemSize;
|
||||
rite -= elemSize;
|
||||
}
|
||||
}
|
||||
if (first < rite)
|
||||
SkQSort_Partition(first, rite, elemSize, compare);
|
||||
if (left < last)
|
||||
SkQSort_Partition(left, last, elemSize, compare);
|
||||
}
|
||||
|
||||
void SkQSort(void* base, size_t count, size_t elemSize, SkQSortCompareProc compare)
|
||||
{
|
||||
SkASSERT(base);
|
||||
SkASSERT(compare);
|
||||
SkASSERT(elemSize > 0);
|
||||
|
||||
if (count <= 1)
|
||||
return;
|
||||
|
||||
SkQSort_Partition((char*)base, (char*)base + (count - 1) * elemSize, elemSize, compare);
|
||||
}
|
||||
|
||||
|
|
|
@ -200,12 +200,10 @@ void GrGLCaps::initFSAASupport(const GrGLContextInfo& ctxInfo) {
|
|||
(int*)&fMSAACoverageModes[0]);
|
||||
// The NV driver seems to return the modes already sorted but the
|
||||
// spec doesn't require this. So we sort.
|
||||
SkQSortCompareProc compareProc =
|
||||
reinterpret_cast<SkQSortCompareProc>(&coverage_mode_compare);
|
||||
SkQSort(&fMSAACoverageModes[0],
|
||||
qsort(&fMSAACoverageModes[0],
|
||||
count,
|
||||
sizeof(MSAACoverageMode),
|
||||
compareProc);
|
||||
SkCastForQSort(coverage_mode_compare));
|
||||
}
|
||||
}
|
||||
if (kNone_MSFBOType != fMSFBOType) {
|
||||
|
|
|
@ -7,7 +7,6 @@
|
|||
*/
|
||||
#include "Test.h"
|
||||
#include "SkRandom.h"
|
||||
#include "SkTSearch.h"
|
||||
#include "SkTSort.h"
|
||||
|
||||
extern "C" {
|
||||
|
@ -41,10 +40,6 @@ static void TestSort(skiatest::Reporter* reporter) {
|
|||
for (int i = 0; i < 10000; i++) {
|
||||
int count = rand.nextRangeU(1, SK_ARRAY_COUNT(array));
|
||||
|
||||
rand_array(rand, array, count);
|
||||
SkQSort(array, count, sizeof(int), compare_int);
|
||||
check_sort(reporter, "Quick", array, count);
|
||||
|
||||
rand_array(rand, array, count);
|
||||
SkTHeapSort<int>(array, count);
|
||||
check_sort(reporter, "Heap", array, count);
|
||||
|
|
|
@ -572,8 +572,6 @@ static void create_diff_images (DiffMetricProc dmp,
|
|||
DiffSummary* summary) {
|
||||
SkASSERT(!baseDir.isEmpty());
|
||||
SkASSERT(!comparisonDir.isEmpty());
|
||||
SkQSortCompareProc sortFileProc =
|
||||
(SkQSortCompareProc)compare_file_name_metrics;
|
||||
|
||||
FileArray baseFiles;
|
||||
FileArray comparisonFiles;
|
||||
|
@ -583,12 +581,12 @@ static void create_diff_images (DiffMetricProc dmp,
|
|||
&comparisonFiles);
|
||||
|
||||
if (!baseFiles.isEmpty()) {
|
||||
SkQSort(baseFiles.begin(), baseFiles.count(),
|
||||
sizeof(SkString*), sortFileProc);
|
||||
qsort(baseFiles.begin(), baseFiles.count(), sizeof(SkString*),
|
||||
SkCastForQSort(compare_file_name_metrics));
|
||||
}
|
||||
if (!comparisonFiles.isEmpty()) {
|
||||
SkQSort(comparisonFiles.begin(), comparisonFiles.count(),
|
||||
sizeof(SkString*), sortFileProc);
|
||||
qsort(comparisonFiles.begin(), comparisonFiles.count(),
|
||||
sizeof(SkString*), SkCastForQSort(compare_file_name_metrics));
|
||||
}
|
||||
|
||||
int i = 0;
|
||||
|
@ -1002,7 +1000,7 @@ argv0, argv0);
|
|||
|
||||
int main (int argc, char ** argv) {
|
||||
DiffMetricProc diffProc = compute_diff_pmcolor;
|
||||
SkQSortCompareProc sortProc = (SkQSortCompareProc) compare_diff_metrics;
|
||||
int (*sortProc)(const void*, const void*) = SkCastForQSort(compare_diff_metrics);
|
||||
|
||||
// Maximum error tolerated in any one color channel in any one pixel before
|
||||
// a difference is reported.
|
||||
|
@ -1045,15 +1043,15 @@ int main (int argc, char ** argv) {
|
|||
continue;
|
||||
}
|
||||
if (!strcmp(argv[i], "--sortbymismatch")) {
|
||||
sortProc = (SkQSortCompareProc) compare_diff_mean_mismatches;
|
||||
sortProc = SkCastForQSort(compare_diff_mean_mismatches);
|
||||
continue;
|
||||
}
|
||||
if (!strcmp(argv[i], "--sortbymaxmismatch")) {
|
||||
sortProc = (SkQSortCompareProc) compare_diff_max_mismatches;
|
||||
sortProc = SkCastForQSort(compare_diff_max_mismatches);
|
||||
continue;
|
||||
}
|
||||
if (!strcmp(argv[i], "--weighted")) {
|
||||
sortProc = (SkQSortCompareProc) compare_diff_weighted;
|
||||
sortProc = SkCastForQSort(compare_diff_weighted);
|
||||
continue;
|
||||
}
|
||||
if (!strcmp(argv[i], "--chromium-release")) {
|
||||
|
@ -1158,7 +1156,7 @@ int main (int argc, char ** argv) {
|
|||
summary.print();
|
||||
|
||||
if (differences.count()) {
|
||||
SkQSort(differences.begin(), differences.count(),
|
||||
qsort(differences.begin(), differences.count(),
|
||||
sizeof(DiffRecord*), sortProc);
|
||||
}
|
||||
|
||||
|
|
Загрузка…
Ссылка в новой задаче