Backout changeset 06f92d065a85 (bug 1377333) because we don't need keys that are that big

This commit is contained in:
Ehsan Akhgari 2017-07-18 23:02:19 -04:00
Родитель 563c00da4d
Коммит 3df4db262f
3 изменённых файлов: 20 добавлений и 19 удалений

Просмотреть файл

@ -72,7 +72,10 @@ PLDHashTable::HashStringKey(const void* aKey)
/* static */ PLDHashNumber
PLDHashTable::HashVoidPtrKeyStub(const void* aKey)
{
return uintptr_t(aKey) >> 2;
// Be careful! We don't want to do the cast to PLDHashNumber which is a
// trimming cast on 64-bit platforms before the shift, otherwise we will lose
// valuable bits from our hash key!
return PLDHashNumber(uintptr_t(aKey) >> 2);
}
/* static */ bool
@ -255,10 +258,10 @@ PLDHashTable::Hash1(PLDHashNumber aHash0)
void
PLDHashTable::Hash2(PLDHashNumber aHash0,
size_t& aHash2Out, size_t& aSizeMaskOut)
uint32_t& aHash2Out, uint32_t& aSizeMaskOut)
{
size_t sizeLog2 = kHashBits - mHashShift;
size_t sizeMask = (PLDHashNumber(1) << sizeLog2) - 1;
uint32_t sizeLog2 = kHashBits - mHashShift;
uint32_t sizeMask = (PLDHashNumber(1) << sizeLog2) - 1;
aSizeMaskOut = sizeMask;
// The incoming aHash0 always has the low bit unset (since we leave it
@ -292,7 +295,7 @@ PLDHashTable::MatchEntryKeyhash(PLDHashEntryHdr* aEntry, PLDHashNumber aKeyHash)
// Compute the address of the indexed entry in table.
PLDHashEntryHdr*
PLDHashTable::AddressEntry(size_t aIndex)
PLDHashTable::AddressEntry(uint32_t aIndex)
{
return reinterpret_cast<PLDHashEntryHdr*>(
mEntryStore.Get() + aIndex * mEntrySize);
@ -370,7 +373,7 @@ PLDHashTable::SearchTable(const void* aKey, PLDHashNumber aKeyHash)
// Collision: double hash.
PLDHashNumber hash2;
size_t sizeMask;
uint32_t sizeMask;
Hash2(aKeyHash, hash2, sizeMask);
// Save the first removed entry pointer so Add() can recycle it. (Only used
@ -430,7 +433,7 @@ PLDHashTable::FindFreeEntry(PLDHashNumber aKeyHash)
// Collision: double hash.
PLDHashNumber hash2;
size_t sizeMask;
uint32_t sizeMask;
Hash2(aKeyHash, hash2, sizeMask);
for (;;) {

Просмотреть файл

@ -15,7 +15,7 @@
#include "mozilla/Types.h"
#include "nscore.h"
typedef size_t PLDHashNumber;
typedef uint32_t PLDHashNumber;
class PLDHashTable;
struct PLDHashTableOps;
@ -490,15 +490,10 @@ public:
}
private:
// Multiplicative hash uses an unsigned pointer sized integer and the golden ratio,
// expressed as a fixed-point pointer sized fraction.
static const uint32_t kHashBits = sizeof(size_t) * 8;
#ifdef HAVE_64BIT_BUILD
// Golden ratio borrowed from http://burtleburtle.net/bob/hash/evahash.html.
static const uint64_t kGoldenRatio = 0X9E3779B97F4A7C13ULL;
#else
// Multiplicative hash uses an unsigned 32 bit integer and the golden ratio,
// expressed as a fixed-point 32-bit fraction.
static const uint32_t kHashBits = 32;
static const uint32_t kGoldenRatio = 0x9E3779B9U;
#endif
static uint32_t HashShift(uint32_t aEntrySize, uint32_t aLength);
@ -527,10 +522,10 @@ private:
}
PLDHashNumber Hash1(PLDHashNumber aHash0);
void Hash2(PLDHashNumber aHash, size_t& aHash2Out, size_t& aSizeMaskOut);
void Hash2(PLDHashNumber aHash, uint32_t& aHash2Out, uint32_t& aSizeMaskOut);
static bool MatchEntryKeyhash(PLDHashEntryHdr* aEntry, PLDHashNumber aHash);
PLDHashEntryHdr* AddressEntry(size_t aIndex);
PLDHashEntryHdr* AddressEntry(uint32_t aIndex);
// We store mHashShift rather than sizeLog2 to optimize the collision-free
// case in SearchTable.

Просмотреть файл

@ -35,7 +35,10 @@ public:
static KeyTypePointer KeyToPointer(KeyType aKey) { return aKey; }
static PLDHashNumber HashKey(KeyTypePointer aKey)
{
return uintptr_t(aKey) >> 2;
// Be careful! We don't want to do the cast to PLDHashNumber which is a
// trimming cast on 64-bit platforms before the shift, otherwise we will
// lose valuable bits from our hash key!
return PLDHashNumber(uintptr_t(aKey) >> 2);
}
enum { ALLOW_MEMMOVE = true };