mirror of
https://gitlab.winehq.org/wine/wine-gecko.git
synced 2024-09-13 09:24:08 -07:00
Bug 940142 - Add a lightweight generic hash key class to nsHashKeys.h. r=bsmedberg
This commit is contained in:
parent
86f4f5d832
commit
6d3953bff9
@ -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__
|
||||
|
Loading…
Reference in New Issue
Block a user