diff options
author | commit-bot@chromium.org <commit-bot@chromium.org@2bbb7eff-a529-9590-31e7-b0007b416f81> | 2014-04-02 17:03:09 +0000 |
---|---|---|
committer | commit-bot@chromium.org <commit-bot@chromium.org@2bbb7eff-a529-9590-31e7-b0007b416f81> | 2014-04-02 17:03:09 +0000 |
commit | 158f64626f8dae7e8437744184860d0110b88609 (patch) | |
tree | 94861ac55b3d8a21ae556fb1602d1dabf95deac0 | |
parent | 52ffbf6be05eb30671529ec86268967fb85c9810 (diff) |
SkTDynamicHash: remove need for Equals(const T&, const Key&) param.
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
-rw-r--r-- | src/core/SkPictureFlat.h | 4 | ||||
-rw-r--r-- | src/core/SkScaledImageCache.cpp | 9 | ||||
-rw-r--r-- | src/core/SkTDynamicHash.h | 10 | ||||
-rw-r--r-- | src/gpu/GrResourceCache.h | 6 | ||||
-rw-r--r-- | src/gpu/GrTMultiMap.h | 9 | ||||
-rw-r--r-- | tests/DynamicHashTest.cpp | 5 |
6 files changed, 13 insertions, 30 deletions
diff --git a/src/core/SkPictureFlat.h b/src/core/SkPictureFlat.h index bd8f66cb7e..f63b9c10a7 100644 --- a/src/core/SkPictureFlat.h +++ b/src/core/SkPictureFlat.h @@ -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; diff --git a/src/core/SkScaledImageCache.cpp b/src/core/SkScaledImageCache.cpp index c436417f28..8320b92181 100644 --- a/src/core/SkScaledImageCache.cpp +++ b/src/core/SkScaledImageCache.cpp @@ -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> {}; + /////////////////////////////////////////////////////////////////////////////// diff --git a/src/core/SkTDynamicHash.h b/src/core/SkTDynamicHash.h index 80570ae0ac..0e34270e0b 100644 --- a/src/core/SkTDynamicHash.h +++ b/src/core/SkTDynamicHash.h @@ -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(); diff --git a/src/gpu/GrResourceCache.h b/src/gpu/GrResourceCache.h index b5953032f6..26423ddc3d 100644 --- a/src/gpu/GrResourceCache.h +++ b/src/gpu/GrResourceCache.h @@ -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; diff --git a/src/gpu/GrTMultiMap.h b/src/gpu/GrTMultiMap.h index c8872143b3..dfa7e5ec7d 100644 --- a/src/gpu/GrTMultiMap.h +++ b/src/gpu/GrTMultiMap.h @@ -18,17 +18,13 @@ 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; }; diff --git a/tests/DynamicHashTest.cpp b/tests/DynamicHashTest.cpp index b2d0f0382c..bb9367b46d 100644 --- a/tests/DynamicHashTest.cpp +++ b/tests/DynamicHashTest.cpp @@ -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 |