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

Unified Diff: src/core/SkPictureFlat.h

Issue 15070011: One SkTSearch to rule them all. Allow key to be of different type than the array. (Closed) Base URL: https://skia.googlecode.com/svn/trunk
Patch Set: fixes to compile on gcc Created 7 years, 7 months 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « src/core/SkPathMeasure.cpp ('k') | src/core/SkPtrRecorder.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/core/SkPictureFlat.h
diff --git a/src/core/SkPictureFlat.h b/src/core/SkPictureFlat.h
index b0446bb93ed2850b20a3d9b348116aa8e9dabd19..b513271f2067d6e8e32fae385e6d58cc21ef5275 100644
--- a/src/core/SkPictureFlat.h
+++ b/src/core/SkPictureFlat.h
@@ -277,22 +277,27 @@ public:
* we see the checksum right away, so that most of the time it is enough
* to short-circuit our comparison.
*/
- static int Compare(const SkFlatData* a, const SkFlatData* b) {
- const uint32_t* stop = a->dataStop();
- const uint32_t* a_ptr = a->dataToCompare() - 1;
- const uint32_t* b_ptr = b->dataToCompare() - 1;
+ static int Compare(const SkFlatData& a, const SkFlatData& b) {
+ const uint32_t* stop = a.dataStop();
+ const uint32_t* a_ptr = a.dataToCompare() - 1;
+ const uint32_t* b_ptr = b.dataToCompare() - 1;
// We use -1 above, so we can pre-increment our pointers in the loop
while (*++a_ptr == *++b_ptr) {}
if (a_ptr == stop) { // sentinel
- SkASSERT(b->dataStop() == b_ptr);
+ SkASSERT(b.dataStop() == b_ptr);
return 0;
}
- SkASSERT(a_ptr < a->dataStop());
- SkASSERT(b_ptr < b->dataStop());
+ SkASSERT(a_ptr < a.dataStop());
+ SkASSERT(b_ptr < b.dataStop());
return (*a_ptr < *b_ptr) ? -1 : 1;
}
+ // Adapts Compare to be used with SkTSearch
+ static bool Less(const SkFlatData& a, const SkFlatData& b) {
+ return Compare(a, b) < 0;
+ }
+
int index() const { return fIndex; }
const void* data() const { return (const char*)this + sizeof(*this); }
void* data() { return (char*)this + sizeof(*this); }
@@ -528,14 +533,14 @@ public:
int hashIndex = ChecksumToHashIndex(flat->checksum());
const SkFlatData* candidate = fHash[hashIndex];
- if (candidate && !SkFlatData::Compare(flat, candidate)) {
+ if (candidate && !SkFlatData::Compare(*flat, *candidate)) {
fController->unalloc(flat);
return candidate;
}
- int index = SkTSearch<SkFlatData>((const SkFlatData**) fSortedData.begin(),
- fSortedData.count(), flat, sizeof(flat),
- &SkFlatData::Compare);
+ int index = SkTSearch<const SkFlatData,
+ SkFlatData::Less>((const SkFlatData**) fSortedData.begin(),
+ fSortedData.count(), flat, sizeof(flat));
if (index >= 0) {
fController->unalloc(flat);
fHash[hashIndex] = fSortedData[index];
« no previous file with comments | « src/core/SkPathMeasure.cpp ('k') | src/core/SkPtrRecorder.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698