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
diff --git a/src/core/SkPictureFlat.h b/src/core/SkPictureFlat.h
index bd8f66c..f63b9c1 100644
--- a/src/core/SkPictureFlat.h
+++ b/src/core/SkPictureFlat.h
@@ -338,7 +338,6 @@
// 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 @@
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 c436417..8320b92 100644
--- a/src/core/SkScaledImageCache.cpp
+++ b/src/core/SkScaledImageCache.cpp
@@ -144,16 +144,13 @@
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 80570ae..0e34270 100644
--- a/src/core/SkTDynamicHash.h
+++ b/src/core/SkTDynamicHash.h
@@ -16,7 +16,6 @@
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 @@
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 @@
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 @@
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 @@
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 b595303..26423dd 100644
--- a/src/gpu/GrResourceCache.h
+++ b/src/gpu/GrResourceCache.h
@@ -122,9 +122,6 @@
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 @@
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 c887214..dfa7e5e 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 @@
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 b2d0f03..bb9367b 100644
--- a/tests/DynamicHashTest.cpp
+++ b/tests/DynamicHashTest.cpp
@@ -17,9 +17,8 @@
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 @@
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