Bug 1187399 - Add a js::DefaultHasher specialization for mozilla::UniquePtr<T> that proxies the UniquePtr's raw pointer to PointerHasher. r=terrence

--HG--
extra : rebase_source : 86db93fe0874c21792554ad000d94939148ea4c6
This commit is contained in:
Nick Fitzgerald 2015-07-24 10:42:00 -04:00
parent e0264d1f80
commit 3bc1833993

View File

@ -17,6 +17,7 @@
#include "mozilla/ReentrancyGuard.h"
#include "mozilla/TemplateLib.h"
#include "mozilla/TypeTraits.h"
#include "mozilla/UniquePtr.h"
#include "js/Utility.h"
@ -586,6 +587,25 @@ template <class T>
struct DefaultHasher<T*> : PointerHasher<T*, mozilla::tl::FloorLog2<sizeof(void*)>::value>
{};
// Specialize hashing policy for mozilla::UniquePtr<T> to proxy the UniquePtr's
// raw pointer to PointerHasher.
template <class T>
struct DefaultHasher<mozilla::UniquePtr<T>>
{
using Lookup = mozilla::UniquePtr<T>;
using PtrHasher = PointerHasher<T*, mozilla::tl::FloorLog2<sizeof(void*)>::value>;
static HashNumber hash(const Lookup& l) {
return PtrHasher::hash(l.get());
}
static bool match(const mozilla::UniquePtr<T>& k, const Lookup& l) {
return PtrHasher::match(k.get(), l.get());
}
static void rekey(mozilla::UniquePtr<T>& k, mozilla::UniquePtr<T>&& newKey) {
k = mozilla::Move(newKey);
}
};
// For doubles, we can xor the two uint32s.
template <>
struct DefaultHasher<double>