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

Unified Diff: src/core/SkTDynamicHash.h

Issue 91453002: Speed up GrResourceCache add and lookup by using TDynamicHash (Closed) Base URL: https://skia.googlecode.com/svn/trunk
Patch Set: Created 7 years 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
Index: src/core/SkTDynamicHash.h
diff --git a/src/core/SkTDynamicHash.h b/src/core/SkTDynamicHash.h
index 4cb44204c85f61130354d25c78c7924249fe66f8..fc668166f9c8f72f8e15157729d3f1fda3686e56 100644
--- a/src/core/SkTDynamicHash.h
+++ b/src/core/SkTDynamicHash.h
@@ -23,7 +23,6 @@ class SkTDynamicHash {
public:
SkTDynamicHash(int initialCapacity=64/sizeof(T*)) {
this->reset(SkNextPow2(initialCapacity > kMinCapacity ? initialCapacity : kMinCapacity));
- SkASSERT(this->validate());
mtklein 2013/12/03 19:02:02 Let's put this guy back. This will never be expen
}
~SkTDynamicHash() {
@@ -53,57 +52,19 @@ public:
void add(T* newEntry) {
SkASSERT(NULL == this->find(GetKey(*newEntry)));
this->maybeGrow();
- SkASSERT(this->validate());
this->innerAdd(newEntry);
- SkASSERT(this->validate());
}
// Remove the entry with this key. We reqire that an entry with this key is present.
void remove(const Key& key) {
SkASSERT(NULL != this->find(key));
this->innerRemove(key);
- SkASSERT(this->validate());
this->maybeShrink();
- SkASSERT(this->validate());
}
-protected:
- // These methods are used by tests only.
-
- int capacity() const { return fCapacity; }
-
- // How many collisions do we go through before finding where this entry should be inserted?
- int countCollisions(const Key& key) const {
- int index = this->firstIndex(key);
- for (int round = 0; round < fCapacity; round++) {
- const T* candidate = fArray[index];
- if (Empty() == candidate || Deleted() == candidate || Equal(*candidate, key)) {
- return round;
- }
- index = this->nextIndex(index, round);
- }
- SkASSERT(0); // countCollisions: should be unreachable
- return -1;
- }
-
-private:
- // We have two special values to indicate an empty or deleted entry.
- static T* Empty() { return reinterpret_cast<T*>(0); } // i.e. NULL
- static T* Deleted() { return reinterpret_cast<T*>(1); } // Also an invalid pointer.
-
- static T** AllocArray(int capacity) {
- return (T**)sk_calloc_throw(sizeof(T*) * capacity); // All cells == Empty().
- }
-
- void reset(int capacity) {
- fCount = 0;
- fDeleted = 0;
- fCapacity = capacity;
- fArray = AllocArray(fCapacity);
- }
-
- bool validate() const {
- #define SKTDYNAMICHASH_CHECK(x) SkASSERT((x)); if (!(x)) return false
+#ifdef SK_DEBUG
mtklein 2013/12/03 19:02:02 This is a little nit, but let's just move the #ifd
+ void validate() const {
+ #define SKTDYNAMICHASH_CHECK(x) SkASSERT((x)); if (!(x)) return
mtklein 2013/12/03 19:02:02 If we're guarding by SK_DEBUG, we can just use SkA
// Is capacity sane?
SKTDYNAMICHASH_CHECK(SkIsPow2(fCapacity));
@@ -150,7 +111,44 @@ private:
}
}
#undef SKTDYNAMICHASH_CHECK
- return true;
+ }
+#else
+ void validate() const { }
+#endif
+
+protected:
+ // These methods are used by tests only.
mtklein 2013/12/03 19:02:02 Can we now pull validate() down here too?
+
+ int capacity() const { return fCapacity; }
+
+ // How many collisions do we go through before finding where this entry should be inserted?
+ int countCollisions(const Key& key) const {
+ int index = this->firstIndex(key);
+ for (int round = 0; round < fCapacity; round++) {
+ const T* candidate = fArray[index];
+ if (Empty() == candidate || Deleted() == candidate || Equal(*candidate, key)) {
+ return round;
+ }
+ index = this->nextIndex(index, round);
+ }
+ SkASSERT(0); // countCollisions: should be unreachable
+ return -1;
+ }
+
+private:
+ // We have two special values to indicate an empty or deleted entry.
+ static T* Empty() { return reinterpret_cast<T*>(0); } // i.e. NULL
+ static T* Deleted() { return reinterpret_cast<T*>(1); } // Also an invalid pointer.
+
+ static T** AllocArray(int capacity) {
+ return (T**)sk_calloc_throw(sizeof(T*) * capacity); // All cells == Empty().
+ }
+
+ void reset(int capacity) {
+ fCount = 0;
+ fDeleted = 0;
+ fCapacity = capacity;
+ fArray = AllocArray(fCapacity);
}
void innerAdd(T* newEntry) {

Powered by Google App Engine
This is Rietveld 408576698