Make it possible to share a comparison func with both SkTSearch and SkQSort
Review URL: http://codereview.appspot.com/6006043/
git-svn-id: http://skia.googlecode.com/svn/trunk@3648 2bbb7eff-a529-9590-31e7-b0007b416f81
diff --git a/include/core/SkPtrRecorder.h b/include/core/SkPtrRecorder.h
index 11fd170..2df84b2 100644
--- a/include/core/SkPtrRecorder.h
+++ b/include/core/SkPtrRecorder.h
@@ -71,7 +71,7 @@
// is not related to its "index".
SkTDArray<Pair> fList;
- static int Cmp(const Pair& a, const Pair& b);
+ static int Cmp(const Pair* a, const Pair* b);
typedef SkRefCnt INHERITED;
};
diff --git a/include/core/SkTSearch.h b/include/core/SkTSearch.h
index d5ab18c..abe727f 100644
--- a/include/core/SkTSearch.h
+++ b/include/core/SkTSearch.h
@@ -47,7 +47,7 @@
template <typename T>
int SkTSearch(const T* base, int count, const T& target, size_t elemSize,
- int (*compare)(const T&, const T&))
+ int (*compare)(const T*, const T*))
{
SkASSERT(count >= 0);
if (count <= 0) {
@@ -63,14 +63,14 @@
int mid = (hi + lo) >> 1;
const T* elem = (const T*)((const char*)base + mid * elemSize);
- if ((*compare)(*elem, target) < 0)
+ if ((*compare)(elem, &target) < 0)
lo = mid + 1;
else
hi = mid;
}
const T* elem = (const T*)((const char*)base + hi * elemSize);
- int pred = (*compare)(*elem, target);
+ int pred = (*compare)(elem, &target);
if (pred != 0) {
if (pred < 0)
hi += 1;
diff --git a/src/core/SkPtrRecorder.cpp b/src/core/SkPtrRecorder.cpp
index e3a9eee..e509464 100644
--- a/src/core/SkPtrRecorder.cpp
+++ b/src/core/SkPtrRecorder.cpp
@@ -18,8 +18,8 @@
fList.reset();
}
-int SkPtrSet::Cmp(const Pair& a, const Pair& b) {
- return (char*)a.fPtr - (char*)b.fPtr;
+int SkPtrSet::Cmp(const Pair* a, const Pair* b) {
+ return (char*)a->fPtr - (char*)b->fPtr;
}
uint32_t SkPtrSet::find(void* ptr) const {