Index: src/core/SkTDynamicHash.h |
diff --git a/src/core/SkTDynamicHash.h b/src/core/SkTDynamicHash.h |
index 4893fb384ff7e6b13a3fea8a814cb523fb2ae33d..3c1ba1a1764c385f6372286c8564b8ececefd7c5 100644 |
--- a/src/core/SkTDynamicHash.h |
+++ b/src/core/SkTDynamicHash.h |
@@ -50,7 +50,6 @@ public: |
void add(T* newEntry) { |
SkASSERT(NULL == this->find(GetKey(*newEntry))); |
this->maybeGrow(); |
- SkASSERT(this->validate()); |
this->innerAdd(newEntry); |
SkASSERT(this->validate()); |
} |
@@ -88,38 +87,29 @@ private: |
bool validate() const { |
#define SKTDYNAMICHASH_CHECK(x) SkASSERT((x)); if (!(x)) return false |
+ static const int kLarge = 50; // Arbitrary, tweak to suit your patience. |
+ // O(1) checks, always done. |
// Is capacity sane? |
SKTDYNAMICHASH_CHECK(SkIsPow2(fCapacity)); |
- // Is fCount correct? |
- int count = 0; |
- for (int i = 0; i < fCapacity; i++) { |
- if (Empty() != fArray[i] && Deleted() != fArray[i]) { |
- count++; |
- } |
- } |
- SKTDYNAMICHASH_CHECK(count == fCount); |
- |
- // Is fDeleted correct? |
- int deleted = 0; |
- for (int i = 0; i < fCapacity; i++) { |
+ // O(N) checks, skipped when very large. |
+ // Are fCount and fDeleted correct, and are all elements findable? |
+ int count = 0, deleted = 0; |
+ for (int i = 0; i < fCapacity && fCount < kLarge * kLarge; i++) { |
if (Deleted() == fArray[i]) { |
deleted++; |
+ } else if (Empty() != fArray[i]) { |
+ count++; |
+ SKTDYNAMICHASH_CHECK(NULL != this->find(GetKey(*fArray[i]))); |
} |
} |
+ SKTDYNAMICHASH_CHECK(count == fCount); |
bsalomon
2014/01/16 15:54:48
won't this fail if fCount is very large?
mtklein
2014/01/16 16:01:45
How large? count and fCount are both ints (as are
|
SKTDYNAMICHASH_CHECK(deleted == fDeleted); |
- // Are all entries findable? |
- for (int i = 0; i < fCapacity; i++) { |
- if (Empty() == fArray[i] || Deleted() == fArray[i]) { |
- continue; |
- } |
- SKTDYNAMICHASH_CHECK(NULL != this->find(GetKey(*fArray[i]))); |
- } |
- |
+ // O(N^2) checks, skipped when large. |
// Are all entries unique? |
- for (int i = 0; i < fCapacity; i++) { |
+ for (int i = 0; i < fCapacity && fCount < kLarge; i++) { |
if (Empty() == fArray[i] || Deleted() == fArray[i]) { |
continue; |
} |