diff options
author | reed@google.com <reed@google.com@2bbb7eff-a529-9590-31e7-b0007b416f81> | 2011-05-04 18:03:00 +0000 |
---|---|---|
committer | reed@google.com <reed@google.com@2bbb7eff-a529-9590-31e7-b0007b416f81> | 2011-05-04 18:03:00 +0000 |
commit | 8d90eeba09484cfc702e82a332c4a7a978a5cfc1 (patch) | |
tree | 67bfea9487fc2c3a320703beb9688cd273ecb39a | |
parent | 2dbd0449bf1dfce02106c5d9394a59498f0d5b9f (diff) |
add find()
git-svn-id: http://skia.googlecode.com/svn/trunk@1243 2bbb7eff-a529-9590-31e7-b0007b416f81
-rw-r--r-- | include/core/SkPtrRecorder.h | 6 | ||||
-rw-r--r-- | src/core/SkPtrRecorder.cpp | 16 |
2 files changed, 22 insertions, 0 deletions
diff --git a/include/core/SkPtrRecorder.h b/include/core/SkPtrRecorder.h index e6e8f55da5..db6c64dfdf 100644 --- a/include/core/SkPtrRecorder.h +++ b/include/core/SkPtrRecorder.h @@ -29,6 +29,12 @@ class SkPtrSet : public SkRefCnt { public: /** + * Search for the specified ptr in the set. If it is found, return its + * 32bit ID [1..N], or if not found, return 0. Always returns 0 for NULL. + */ + uint32_t find(void*) const; + + /** * Add the specified ptr to the set, returning a unique 32bit ID for it * [1...N]. Duplicate ptrs will return the same ID. * diff --git a/src/core/SkPtrRecorder.cpp b/src/core/SkPtrRecorder.cpp index fa640cb32b..6d5d95d6f4 100644 --- a/src/core/SkPtrRecorder.cpp +++ b/src/core/SkPtrRecorder.cpp @@ -15,6 +15,22 @@ int SkPtrSet::Cmp(const Pair& a, const Pair& b) { return (char*)a.fPtr - (char*)b.fPtr; } +uint32_t SkPtrSet::find(void* ptr) const { + if (NULL == ptr) { + return 0; + } + + int count = fList.count(); + Pair pair; + pair.fPtr = ptr; + + int index = SkTSearch<Pair>(fList.begin(), count, pair, sizeof(pair), &Cmp); + if (index < 0) { + return 0; + } + return fList[index].fIndex; +} + uint32_t SkPtrSet::add(void* ptr) { if (NULL == ptr) { return 0; |