зеркало из https://github.com/mozilla/gecko-dev.git
Bug 940142 - Add a lightweight generic hash key class to nsHashKeys.h. r=bsmedberg
This commit is contained in:
Родитель
15ea1ba33f
Коммит
579513aaf3
|
@ -33,32 +33,6 @@ using std::max;
|
|||
using std::min;
|
||||
using mozilla::gfx::DrawTarget;
|
||||
|
||||
/**
|
||||
* Hashtable key class to use with objects for which Hash() and operator==()
|
||||
* are defined.
|
||||
* XXX(seth): This will get moved to xpcom/glue/nsHashKeys.h in a followup bug.
|
||||
*/
|
||||
template <typename T>
|
||||
class nsGenericHashKey : public PLDHashEntryHdr
|
||||
{
|
||||
public:
|
||||
typedef const T& KeyType;
|
||||
typedef const T* KeyTypePointer;
|
||||
|
||||
nsGenericHashKey(KeyTypePointer aKey) : mKey(*aKey) { }
|
||||
nsGenericHashKey(const nsGenericHashKey<T>& aOther) : mKey(aOther.mKey) { }
|
||||
|
||||
KeyType GetKey() const { return mKey; }
|
||||
bool KeyEquals(KeyTypePointer aKey) const { return *aKey == mKey; }
|
||||
|
||||
static KeyTypePointer KeyToPointer(KeyType aKey) { return &aKey; }
|
||||
static PLDHashNumber HashKey(KeyTypePointer aKey) { return aKey->Hash(); }
|
||||
enum { ALLOW_MEMMOVE = true };
|
||||
|
||||
private:
|
||||
T mKey;
|
||||
};
|
||||
|
||||
namespace mozilla {
|
||||
namespace image {
|
||||
|
||||
|
|
|
@ -62,6 +62,7 @@ HashString(const nsACString& aStr)
|
|||
* nsCharPtrHashKey
|
||||
* nsUnicharPtrHashKey
|
||||
* nsHashableHashKey
|
||||
* nsGenericHashKey
|
||||
*/
|
||||
|
||||
/**
|
||||
|
@ -585,4 +586,29 @@ private:
|
|||
nsCOMPtr<nsIHashable> mKey;
|
||||
};
|
||||
|
||||
/**
|
||||
* Hashtable key class to use with objects for which Hash() and operator==()
|
||||
* are defined.
|
||||
*/
|
||||
template <typename T>
|
||||
class nsGenericHashKey : public PLDHashEntryHdr
|
||||
{
|
||||
public:
|
||||
typedef const T& KeyType;
|
||||
typedef const T* KeyTypePointer;
|
||||
|
||||
nsGenericHashKey(KeyTypePointer aKey) : mKey(*aKey) { }
|
||||
nsGenericHashKey(const nsGenericHashKey<T>& aOther) : mKey(aOther.mKey) { }
|
||||
|
||||
KeyType GetKey() const { return mKey; }
|
||||
bool KeyEquals(KeyTypePointer aKey) const { return *aKey == mKey; }
|
||||
|
||||
static KeyTypePointer KeyToPointer(KeyType aKey) { return &aKey; }
|
||||
static PLDHashNumber HashKey(KeyTypePointer aKey) { return aKey->Hash(); }
|
||||
enum { ALLOW_MEMMOVE = true };
|
||||
|
||||
private:
|
||||
T mKey;
|
||||
};
|
||||
|
||||
#endif // nsTHashKeys_h__
|
||||
|
|
Загрузка…
Ссылка в новой задаче