diff options
author | 2013-05-17 19:05:03 +0000 | |
---|---|---|
committer | 2013-05-17 19:05:03 +0000 | |
commit | 20f7f173e05b60f541910d0c1da9850ac73e2958 (patch) | |
tree | 6d06f639a90e18a85b6188eed1a15854b96888fd /src/core/SkBitmapHeap.cpp | |
parent | d7c37425805d5909ed5601bf2fbf14d5c8b4c86b (diff) |
One SkTSearch to rule them all. Allow key to be of different type than the array.
R=bungeman@google.com
Review URL: https://codereview.chromium.org/15070011
git-svn-id: http://skia.googlecode.com/svn/trunk@9182 2bbb7eff-a529-9590-31e7-b0007b416f81
Diffstat (limited to 'src/core/SkBitmapHeap.cpp')
-rw-r--r-- | src/core/SkBitmapHeap.cpp | 41 |
1 files changed, 20 insertions, 21 deletions
diff --git a/src/core/SkBitmapHeap.cpp b/src/core/SkBitmapHeap.cpp index 48194b1eaa..f3428db64f 100644 --- a/src/core/SkBitmapHeap.cpp +++ b/src/core/SkBitmapHeap.cpp @@ -38,26 +38,24 @@ void SkBitmapHeapEntry::addReferences(int count) { /////////////////////////////////////////////////////////////////////////////// -int SkBitmapHeap::LookupEntry::Compare(const SkBitmapHeap::LookupEntry *a, - const SkBitmapHeap::LookupEntry *b) { - if (a->fGenerationId < b->fGenerationId) { - return -1; - } else if (a->fGenerationId > b->fGenerationId) { - return 1; - } else if (a->fPixelOffset < b->fPixelOffset) { - return -1; - } else if (a->fPixelOffset > b->fPixelOffset) { - return 1; - } else if (a->fWidth < b->fWidth) { - return -1; - } else if (a->fWidth > b->fWidth) { - return 1; - } else if (a->fHeight < b->fHeight) { - return -1; - } else if (a->fHeight > b->fHeight) { - return 1; +bool SkBitmapHeap::LookupEntry::Less(const SkBitmapHeap::LookupEntry& a, + const SkBitmapHeap::LookupEntry& b) { + if (a.fGenerationId < b.fGenerationId) { + return true; + } else if (a.fGenerationId > b.fGenerationId) { + return false; + } else if (a.fPixelOffset < b.fPixelOffset) { + return true; + } else if (a.fPixelOffset > b.fPixelOffset) { + return false; + } else if (a.fWidth < b.fWidth) { + return true; + } else if (a.fWidth > b.fWidth) { + return false; + } else if (a.fHeight < b.fHeight) { + return true; } - return 0; + return false; } /////////////////////////////////////////////////////////////////////////////// @@ -231,9 +229,10 @@ size_t SkBitmapHeap::freeMemoryIfPossible(size_t bytesToFree) { } int SkBitmapHeap::findInLookupTable(const LookupEntry& indexEntry, SkBitmapHeapEntry** entry) { - int index = SkTSearch<const LookupEntry>((const LookupEntry**)fLookupTable.begin(), + int index = SkTSearch<const LookupEntry, LookupEntry::Less>( + (const LookupEntry**)fLookupTable.begin(), fLookupTable.count(), - &indexEntry, sizeof(void*), LookupEntry::Compare); + &indexEntry, sizeof(void*)); if (index < 0) { // insert ourselves into the bitmapIndex |