From c967795b8f63bda26b76694e08a642136e22cb5b Mon Sep 17 00:00:00 2001 From: "bsalomon@google.com" Date: Tue, 10 Apr 2012 21:03:23 +0000 Subject: 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 --- include/core/SkPtrRecorder.h | 2 +- include/core/SkTSearch.h | 6 +++--- src/core/SkPtrRecorder.cpp | 4 ++-- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/include/core/SkPtrRecorder.h b/include/core/SkPtrRecorder.h index 11fd17043e..2df84b245a 100644 --- a/include/core/SkPtrRecorder.h +++ b/include/core/SkPtrRecorder.h @@ -71,7 +71,7 @@ private: // is not related to its "index". SkTDArray 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 d5ab18ceda..abe727fe03 100644 --- a/include/core/SkTSearch.h +++ b/include/core/SkTSearch.h @@ -47,7 +47,7 @@ int SkTSearch(const T* base, int count, const T& target, size_t elemSize) template 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 SkTSearch(const T* base, int count, const T& target, size_t elemSize, 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 e3a9eee3bb..e509464a4d 100644 --- a/src/core/SkPtrRecorder.cpp +++ b/src/core/SkPtrRecorder.cpp @@ -18,8 +18,8 @@ void SkPtrSet::reset() { 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 { -- cgit v1.2.3