SkTDynamicHash: remove need for Equals(const T&, const Key&) param.
authorcommit-bot@chromium.org <commit-bot@chromium.org@2bbb7eff-a529-9590-31e7-b0007b416f81>
Wed, 2 Apr 2014 17:03:09 +0000 (17:03 +0000)
committercommit-bot@chromium.org <commit-bot@chromium.org@2bbb7eff-a529-9590-31e7-b0007b416f81>
Wed, 2 Apr 2014 17:03:09 +0000 (17:03 +0000)
All implementations are relying on bool operator==(const Key&, const Key&)
anyway, which makes total sense, so just make that required.

BUG=skia:
R=bsalomon@google.com, mtklein@google.com

Author: mtklein@chromium.org

Review URL: https://codereview.chromium.org/222343002

git-svn-id: http://skia.googlecode.com/svn/trunk@14027 2bbb7eff-a529-9590-31e7-b0007b416f81

src/core/SkPictureFlat.h
src/core/SkScaledImageCache.cpp
src/core/SkTDynamicHash.h
src/gpu/GrResourceCache.h
src/gpu/GrTMultiMap.h
tests/DynamicHashTest.cpp

index bd8f66cb7e4ab73c6ca0d05b7421a63ac8ed2f4e..f63b9c10a72495c1fe22758ae035c9e990cc621d 100644 (file)
@@ -338,7 +338,6 @@ private:
     // For SkTDynamicHash.
     static const SkFlatData& Identity(const SkFlatData& flat) { return flat; }
     static uint32_t Hash(const SkFlatData& flat) { return flat.checksum(); }
-    static bool Equal(const SkFlatData& a, const SkFlatData& b) { return a == b; }
 
     void setIndex(int index) { fIndex = index; }
     uint8_t* data() { return (uint8_t*)this + sizeof(*this); }
@@ -564,8 +563,7 @@ private:
     SkTDArray<const SkFlatData*> fIndexedData;
 
     // For SkFlatData -> cached SkFlatData, which has index().
-    SkTDynamicHash<SkFlatData, SkFlatData,
-                   SkFlatData::Identity, SkFlatData::Hash, SkFlatData::Equal> fHash;
+    SkTDynamicHash<SkFlatData, SkFlatData, SkFlatData::Identity, SkFlatData::Hash> fHash;
 };
 
 typedef SkFlatDictionary<SkPaint, SkPaint::FlatteningTraits> SkPaintDictionary;
index c436417f281b7463737c27bb31be758c8423ff7c..8320b921816c6fe526455abf26776a9888283cf5 100644 (file)
@@ -144,16 +144,13 @@ uint32_t hash_from_key(const SkScaledImageCache::Key& key) {
     return key.fHash;
 }
 
-bool eq_rec_key(const SkScaledImageCache::Rec& rec, const SkScaledImageCache::Key& key) {
-    return rec.fKey == key;
-}
-}
+}  // namespace
 
 class SkScaledImageCache::Hash : public SkTDynamicHash<SkScaledImageCache::Rec,
                                                        SkScaledImageCache::Key,
                                                        key_from_rec,
-                                                       hash_from_key,
-                                                       eq_rec_key> {};
+                                                       hash_from_key> {};
+
 
 ///////////////////////////////////////////////////////////////////////////////
 
index 80570ae0acb9b4d86f373ad85230da63e571b09e..0e34270e0b459765f705405e85106706c48a9a9d 100644 (file)
@@ -16,7 +16,6 @@ template <typename T,
           typename Key,
           const Key& (GetKey)(const T&),
           uint32_t (Hash)(const Key&),
-          bool (Equal)(const T&, const Key&),
           int kGrowPercent = 75>  // Larger -> more memory efficient, but slower.
 class SkTDynamicHash {
 public:
@@ -65,7 +64,7 @@ public:
             if (Empty() == candidate) {
                 return NULL;
             }
-            if (Deleted() != candidate && Equal(*candidate, key)) {
+            if (Deleted() != candidate && GetKey(*candidate) == key) {
                 return candidate;
             }
             index = this->nextIndex(index, round);
@@ -99,7 +98,7 @@ protected:
         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)) {
+            if (Empty() == candidate || Deleted() == candidate || GetKey(*candidate) == key) {
                 return round;
             }
             index = this->nextIndex(index, round);
@@ -149,8 +148,7 @@ private:
                         continue;
                     }
                     SKTDYNAMICHASH_CHECK(fArray[i] != fArray[j]);
-                    SKTDYNAMICHASH_CHECK(!Equal(*fArray[i], GetKey(*fArray[j])));
-                    SKTDYNAMICHASH_CHECK(!Equal(*fArray[j], GetKey(*fArray[i])));
+                    SKTDYNAMICHASH_CHECK(!(GetKey(*fArray[i]) == GetKey(*fArray[j])));
                 }
             }
         }
@@ -181,7 +179,7 @@ private:
         int index = firstIndex;
         for (int round = 0; round < fCapacity; round++) {
             const T* candidate = fArray[index];
-            if (Deleted() != candidate && Equal(*candidate, key)) {
+            if (Deleted() != candidate && GetKey(*candidate) == key) {
                 fDeleted++;
                 fCount--;
                 fArray[index] = Deleted();
index b5953032f617b5e036fede5bffd1828b16e9dba6..26423ddc3dc9e60fbfe6c0eb3848b899e0745192 100644 (file)
@@ -122,9 +122,6 @@ public:
 
     static const GrResourceKey& GetKey(const GrResourceEntry& e) { return e.key(); }
     static uint32_t Hash(const GrResourceKey& key) { return key.getHash(); }
-    static bool Equal(const GrResourceEntry& a, const GrResourceKey& b) {
-        return a.key() == b;
-    }
 #ifdef SK_DEBUG
     void validate() const;
 #else
@@ -321,8 +318,7 @@ private:
     GrTMultiMap<GrResourceEntry,
                 GrResourceKey,
                 GrResourceEntry::GetKey,
-                GrResourceEntry::Hash,
-                GrResourceEntry::Equal> fCache;
+                GrResourceEntry::Hash> fCache;
 
     // We're an internal doubly linked list
     typedef SkTInternalLList<GrResourceEntry> EntryList;
index c8872143b38e6210aa76e728e25ac616b0feaa58..dfa7e5ec7d01e9fedb35019f3a67d8e3bdc925cd 100644 (file)
 template <typename T,
           typename Key,
           const Key& (GetKey)(const T&),
-          uint32_t (Hash)(const Key&),
-          bool (Equal)(const T&, const Key&)>
+          uint32_t (Hash)(const Key&)>
 class GrTMultiMap {
     struct ValueList {
         explicit ValueList(T* value) : fValue(value), fNext(NULL) {}
 
         static const Key& ListGetKey(const ValueList& e) { return GetKey(*e.fValue); }
         static uint32_t ListHash(const Key& key) { return Hash(key); }
-        static bool ListEqual(const ValueList& a, const Key& b) {
-            return Equal(*a.fValue, b);
-        }
         T* fValue;
         ValueList* fNext;
     };
@@ -111,8 +107,7 @@ private:
     SkTDynamicHash<ValueList,
                    Key,
                    ValueList::ListGetKey,
-                   ValueList::ListHash,
-                   ValueList::ListEqual> fHash;
+                   ValueList::ListHash> fHash;
     int fCount;
 };
 
index b2d0f0382c57ae5b353761d72ebd9139cd5973a6..bb9367b46df5c4d0a23000341c61a68c529afe81 100644 (file)
@@ -17,9 +17,8 @@ struct Entry {
 
 const int& GetKey(const Entry& entry) { return entry.key; }
 uint32_t GetHash(const int& key) { return key; }
-bool AreEqual(const Entry& entry, const int& key) { return entry.key == key; }
 
-class Hash : public SkTDynamicHash<Entry, int, GetKey, GetHash, AreEqual> {
+class Hash : public SkTDynamicHash<Entry, int, GetKey, GetHash> {
 public:
     Hash() : INHERITED() {}
 
@@ -28,7 +27,7 @@ public:
     int countCollisions(const int& key) const { return this->INHERITED::countCollisions(key); }
 
 private:
-    typedef SkTDynamicHash<Entry, int, GetKey, GetHash, AreEqual> INHERITED;
+    typedef SkTDynamicHash<Entry, int, GetKey, GetHash> INHERITED;
 };
 
 }  // namespace