add find()
git-svn-id: http://skia.googlecode.com/svn/trunk@1243 2bbb7eff-a529-9590-31e7-b0007b416f81
diff --git a/include/core/SkPtrRecorder.h b/include/core/SkPtrRecorder.h
index e6e8f55..db6c64d 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 fa640cb..6d5d95d 100644
--- a/src/core/SkPtrRecorder.cpp
+++ b/src/core/SkPtrRecorder.cpp
@@ -15,6 +15,22 @@
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;