Bug 1121760 (part 6) - Move all remaining PL_DHash*() functions into PLDHashTable. r=poiru.

This commit is contained in:
Nicholas Nethercote 2015-09-14 14:23:47 -07:00
parent 93fcb9414c
commit ac3ae5e6c1
38 changed files with 159 additions and 189 deletions

View File

@ -210,8 +210,8 @@ NS_GetContentList(nsINode* aRootNode,
{
ContentListHashtableHashKey,
ContentListHashtableMatchEntry,
PL_DHashMoveEntryStub,
PL_DHashClearEntryStub
PLDHashTable::MoveEntryStub,
PLDHashTable::ClearEntryStub
};
// Initialize the hashtable if needed.
@ -313,8 +313,8 @@ GetFuncStringContentList(nsINode* aRootNode,
{
FuncStringContentListHashtableHashKey,
FuncStringContentListHashtableMatchEntry,
PL_DHashMoveEntryStub,
PL_DHashClearEntryStub
PLDHashTable::MoveEntryStub,
PLDHashTable::ClearEntryStub
};
// Initialize the hashtable if needed.

View File

@ -508,9 +508,9 @@ nsContentUtils::Init()
if (!sEventListenerManagersHash) {
static const PLDHashTableOps hash_table_ops =
{
PL_DHashVoidPtrKeyStub,
PL_DHashMatchEntryStub,
PL_DHashMoveEntryStub,
PLDHashTable::HashVoidPtrKeyStub,
PLDHashTable::MatchEntryStub,
PLDHashTable::MoveEntryStub,
EventListenerManagerHashClearEntry,
EventListenerManagerHashInitEntry
};

View File

@ -3956,9 +3956,9 @@ nsDocument::SetSubDocumentFor(Element* aElement, nsIDocument* aSubDoc)
static const PLDHashTableOps hash_table_ops =
{
PL_DHashVoidPtrKeyStub,
PL_DHashMatchEntryStub,
PL_DHashMoveEntryStub,
PLDHashTable::HashVoidPtrKeyStub,
PLDHashTable::MatchEntryStub,
PLDHashTable::MoveEntryStub,
SubDocClearEntry,
SubDocInitEntry
};

View File

@ -265,7 +265,7 @@ nsPropertyTable::PropertyList::PropertyList(nsIAtom *aName,
void *aDtorData,
bool aTransfer)
: mName(aName),
mObjectValueMap(PL_DHashGetStubOps(), sizeof(PropertyListMapEntry)),
mObjectValueMap(PLDHashTable::StubOps(), sizeof(PropertyListMapEntry)),
mDtorFunc(aDtorFunc),
mDtorData(aDtorData),
mTransfer(aTransfer),

View File

@ -106,7 +106,7 @@ static const PLDHashTableOps hash_table_ops =
{
GlobalNameHashHashKey,
GlobalNameHashMatchEntry,
PL_DHashMoveEntryStub,
PLDHashTable::MoveEntryStub,
GlobalNameHashClearEntry,
GlobalNameHashInitEntry
};

View File

@ -400,7 +400,7 @@ CreateNPObjWrapperTable()
}
sNPObjWrappers =
new PLDHashTable(PL_DHashGetStubOps(), sizeof(NPObjWrapperHashEntry));
new PLDHashTable(PLDHashTable::StubOps(), sizeof(NPObjWrapperHashEntry));
return true;
}

View File

@ -752,9 +752,9 @@ XULDocument::AddBroadcastListenerFor(Element& aBroadcaster, Element& aListener,
}
static const PLDHashTableOps gOps = {
PL_DHashVoidPtrKeyStub,
PL_DHashMatchEntryStub,
PL_DHashMoveEntryStub,
PLDHashTable::HashVoidPtrKeyStub,
PLDHashTable::MatchEntryStub,
PLDHashTable::MoveEntryStub,
ClearBroadcasterMapEntry,
nullptr
};

View File

@ -21,7 +21,7 @@
*/
class nsContentSupportMap {
public:
nsContentSupportMap() : mMap(PL_DHashGetStubOps(), sizeof(Entry)) { }
nsContentSupportMap() : mMap(PLDHashTable::StubOps(), sizeof(Entry)) { }
~nsContentSupportMap() { }
nsresult Put(nsIContent* aElement, nsTemplateMatch* aMatch) {

View File

@ -19,7 +19,7 @@ protected:
PLDHashTable mTable;
public:
nsTemplateMap() : mTable(PL_DHashGetStubOps(), sizeof(Entry)) { }
nsTemplateMap() : mTable(PLDHashTable::StubOps(), sizeof(Entry)) { }
~nsTemplateMap() { }

View File

@ -630,7 +630,7 @@ public:
StringHash,
HashMatchEntry,
MoveEntry,
PL_DHashClearEntryStub,
PLDHashTable::ClearEntryStub,
nullptr
};

View File

@ -173,7 +173,7 @@ Native2WrappedNativeMap::newMap(int length)
}
Native2WrappedNativeMap::Native2WrappedNativeMap(int length)
: mTable(new PLDHashTable(PL_DHashGetStubOps(), sizeof(Entry), length))
: mTable(new PLDHashTable(PLDHashTable::StubOps(), sizeof(Entry), length))
{
}
@ -201,8 +201,8 @@ const struct PLDHashTableOps IID2WrappedJSClassMap::Entry::sOps =
{
HashIIDPtrKey,
MatchIIDPtrKey,
PL_DHashMoveEntryStub,
PL_DHashClearEntryStub
PLDHashTable::MoveEntryStub,
PLDHashTable::ClearEntryStub
};
// static
@ -229,8 +229,8 @@ const struct PLDHashTableOps IID2NativeInterfaceMap::Entry::sOps =
{
HashIIDPtrKey,
MatchIIDPtrKey,
PL_DHashMoveEntryStub,
PL_DHashClearEntryStub
PLDHashTable::MoveEntryStub,
PLDHashTable::ClearEntryStub
};
// static
@ -273,7 +273,7 @@ ClassInfo2NativeSetMap::newMap(int length)
}
ClassInfo2NativeSetMap::ClassInfo2NativeSetMap(int length)
: mTable(new PLDHashTable(PL_DHashGetStubOps(), sizeof(Entry), length))
: mTable(new PLDHashTable(PLDHashTable::StubOps(), sizeof(Entry), length))
{
}
@ -301,7 +301,7 @@ ClassInfo2WrappedNativeProtoMap::newMap(int length)
}
ClassInfo2WrappedNativeProtoMap::ClassInfo2WrappedNativeProtoMap(int length)
: mTable(new PLDHashTable(PL_DHashGetStubOps(), sizeof(Entry), length))
: mTable(new PLDHashTable(PLDHashTable::StubOps(), sizeof(Entry), length))
{
}
@ -401,8 +401,8 @@ const struct PLDHashTableOps NativeSetMap::Entry::sOps =
{
HashNativeKey,
Match,
PL_DHashMoveEntryStub,
PL_DHashClearEntryStub
PLDHashTable::MoveEntryStub,
PLDHashTable::ClearEntryStub
};
// static
@ -456,7 +456,7 @@ const struct PLDHashTableOps IID2ThisTranslatorMap::Entry::sOps =
{
HashIIDPtrKey,
Match,
PL_DHashMoveEntryStub,
PLDHashTable::MoveEntryStub,
Clear
};
@ -527,8 +527,8 @@ const struct PLDHashTableOps XPCNativeScriptableSharedMap::Entry::sOps =
{
Hash,
Match,
PL_DHashMoveEntryStub,
PL_DHashClearEntryStub
PLDHashTable::MoveEntryStub,
PLDHashTable::ClearEntryStub
};
// static
@ -585,7 +585,7 @@ XPCWrappedNativeProtoMap::newMap(int length)
}
XPCWrappedNativeProtoMap::XPCWrappedNativeProtoMap(int length)
: mTable(new PLDHashTable(PL_DHashGetStubOps(), sizeof(PLDHashEntryStub),
: mTable(new PLDHashTable(PLDHashTable::StubOps(), sizeof(PLDHashEntryStub),
length))
{
}

View File

@ -16,7 +16,7 @@
// Note that most of the declarations for hash table entries begin with
// a pointer to something or another. This makes them look enough like
// the PLDHashEntryStub struct that the default OPs (PL_DHashGetStubOps())
// the PLDHashEntryStub struct that the default ops (PLDHashTable::StubOps())
// just do the right thing for most of our needs.
// no virtuals in the maps - all the common stuff inlined

View File

@ -69,10 +69,10 @@ PlaceholderMapMatchEntry(PLDHashTable *table, const PLDHashEntryHdr *hdr,
}
static const PLDHashTableOps PlaceholderMapOps = {
PL_DHashVoidPtrKeyStub,
PLDHashTable::HashVoidPtrKeyStub,
PlaceholderMapMatchEntry,
PL_DHashMoveEntryStub,
PL_DHashClearEntryStub,
PLDHashTable::MoveEntryStub,
PLDHashTable::ClearEntryStub,
nullptr
};

View File

@ -359,7 +359,7 @@ RuleHash_NameSpaceTable_MatchEntry(PLDHashTable *table,
}
static const PLDHashTableOps RuleHash_TagTable_Ops = {
PL_DHashVoidPtrKeyStub,
PLDHashTable::HashVoidPtrKeyStub,
RuleHash_TagTable_MatchEntry,
RuleHash_TagTable_MoveEntry,
RuleHash_TagTable_ClearEntry,
@ -369,7 +369,7 @@ static const PLDHashTableOps RuleHash_TagTable_Ops = {
// Case-sensitive ops.
static const RuleHashTableOps RuleHash_ClassTable_CSOps = {
{
PL_DHashVoidPtrKeyStub,
PLDHashTable::HashVoidPtrKeyStub,
RuleHash_CSMatchEntry,
RuleHash_MoveEntry,
RuleHash_ClearEntry,
@ -393,7 +393,7 @@ static const RuleHashTableOps RuleHash_ClassTable_CIOps = {
// Case-sensitive ops.
static const RuleHashTableOps RuleHash_IdTable_CSOps = {
{
PL_DHashVoidPtrKeyStub,
PLDHashTable::HashVoidPtrKeyStub,
RuleHash_CSMatchEntry,
RuleHash_MoveEntry,
RuleHash_ClearEntry,
@ -850,8 +850,8 @@ AtomSelector_GetKey(PLDHashTable *table, const PLDHashEntryHdr *hdr)
// Case-sensitive ops.
static const PLDHashTableOps AtomSelector_CSOps = {
PL_DHashVoidPtrKeyStub,
PL_DHashMatchEntryStub,
PLDHashTable::HashVoidPtrKeyStub,
PLDHashTable::MatchEntryStub,
AtomSelector_MoveEntry,
AtomSelector_ClearEntry,
AtomSelector_InitEntry
@ -3516,8 +3516,8 @@ InitWeightEntry(PLDHashEntryHdr *hdr, const void *key)
static const PLDHashTableOps gRulesByWeightOps = {
HashIntKey,
MatchWeightEntry,
PL_DHashMoveEntryStub,
PL_DHashClearEntryStub,
PLDHashTable::MoveEntryStub,
PLDHashTable::ClearEntryStub,
InitWeightEntry
};

View File

@ -171,7 +171,7 @@ MappedAttrTable_MatchEntry(PLDHashTable *table, const PLDHashEntryHdr *hdr,
static const PLDHashTableOps MappedAttrTable_Ops = {
MappedAttrTable_HashKey,
MappedAttrTable_MatchEntry,
PL_DHashMoveEntryStub,
PLDHashTable::MoveEntryStub,
MappedAttrTable_ClearEntry,
nullptr
};
@ -222,7 +222,7 @@ LangRuleTable_InitEntry(PLDHashEntryHdr *hdr, const void *key)
static const PLDHashTableOps LangRuleTable_Ops = {
LangRuleTable_HashKey,
LangRuleTable_MatchEntry,
PL_DHashMoveEntryStub,
PLDHashTable::MoveEntryStub,
LangRuleTable_ClearEntry,
LangRuleTable_InitEntry
};

View File

@ -104,7 +104,7 @@ nsRuleNode::ChildrenHashHashKey(PLDHashTable *aTable, const void *aKey)
static_cast<const nsRuleNode::Key*>(aKey);
// Disagreement on importance and level for the same rule is extremely
// rare, so hash just on the rule.
return PL_DHashVoidPtrKeyStub(aTable, key->mRule);
return PLDHashTable::HashVoidPtrKeyStub(aTable, key->mRule);
}
/* static */ bool
@ -127,8 +127,8 @@ nsRuleNode::ChildrenHashOps = {
// large size allocations.
ChildrenHashHashKey,
ChildrenHashMatchEntry,
PL_DHashMoveEntryStub,
PL_DHashClearEntryStub,
PLDHashTable::MoveEntryStub,
PLDHashTable::ClearEntryStub,
nullptr
};

View File

@ -31,8 +31,8 @@ SpanningCellSorter::~SpanningCellSorter()
SpanningCellSorter::HashTableOps = {
HashTableHashKey,
HashTableMatchEntry,
PL_DHashMoveEntryStub,
PL_DHashClearEntryStub,
PLDHashTable::MoveEntryStub,
PLDHashTable::ClearEntryStub,
nullptr
};

View File

@ -80,9 +80,9 @@ static bool gShouldCleanupDeadNodes = false;
static PLDHashTableOps pref_HashTableOps = {
PL_DHashStringKey,
PLDHashTable::HashStringKey,
matchPrefEntry,
PL_DHashMoveEntryStub,
PLDHashTable::MoveEntryStub,
clearPrefEntry,
nullptr,
};

View File

@ -88,9 +88,9 @@ RequestHashInitEntry(PLDHashEntryHdr *entry, const void *key)
static const PLDHashTableOps sRequestHashOps =
{
PL_DHashVoidPtrKeyStub,
PLDHashTable::HashVoidPtrKeyStub,
RequestHashMatchEntry,
PL_DHashMoveEntryStub,
PLDHashTable::MoveEntryStub,
RequestHashClearEntry,
RequestHashInitEntry
};

View File

@ -68,9 +68,9 @@ public:
static PLDHashNumber HashKey(KeyTypePointer aKey)
{
// PL_DHashStringKey doesn't use the table parameter, so we can safely
// pass nullptr
return PL_DHashStringKey(nullptr, aKey);
// PLDHashTable::HashStringKey doesn't use the table parameter, so we can
// safely pass nullptr
return PLDHashTable::HashStringKey(nullptr, aKey);
}
enum { ALLOW_MEMMOVE = true };

View File

@ -85,8 +85,8 @@ StringCompare(PLDHashTable *table, const PLDHashEntryHdr *entry,
static const PLDHashTableOps ops = {
StringHash,
StringCompare,
PL_DHashMoveEntryStub,
PL_DHashClearEntryStub,
PLDHashTable::MoveEntryStub,
PLDHashTable::ClearEntryStub,
nullptr
};

View File

@ -50,18 +50,18 @@ static PLDHashNumber
static const PLDHashTableOps EntityToUnicodeOps = {
PL_DHashStringKey,
PLDHashTable::HashStringKey,
matchNodeString,
PL_DHashMoveEntryStub,
PL_DHashClearEntryStub,
PLDHashTable::MoveEntryStub,
PLDHashTable::ClearEntryStub,
nullptr,
};
static const PLDHashTableOps UnicodeToEntityOps = {
hashUnicodeValue,
matchNodeUnicode,
PL_DHashMoveEntryStub,
PL_DHashClearEntryStub,
PLDHashTable::MoveEntryStub,
PLDHashTable::ClearEntryStub,
nullptr,
};

View File

@ -161,7 +161,7 @@ Assertion::Assertion(nsIRDFResource* aSource)
NS_ADDREF(mSource);
u.hash.mPropertyHash =
new PLDHashTable(PL_DHashGetStubOps(), sizeof(Entry));
new PLDHashTable(PLDHashTable::StubOps(), sizeof(Entry));
}
Assertion::Assertion(nsIRDFResource* aSource,
@ -734,8 +734,8 @@ NS_NewRDFInMemoryDataSource(nsISupports* aOuter, const nsIID& aIID, void** aResu
InMemoryDataSource::InMemoryDataSource(nsISupports* aOuter)
: mForwardArcs(PL_DHashGetStubOps(), sizeof(Entry))
, mReverseArcs(PL_DHashGetStubOps(), sizeof(Entry))
: mForwardArcs(PLDHashTable::StubOps(), sizeof(Entry))
, mReverseArcs(PLDHashTable::StubOps(), sizeof(Entry))
, mNumObservers(0)
, mReadCount(0)
{

View File

@ -141,8 +141,8 @@ struct ResourceHashEntry : public PLDHashEntryHdr {
static const PLDHashTableOps gResourceTableOps = {
ResourceHashEntry::HashKey,
ResourceHashEntry::MatchEntry,
PL_DHashMoveEntryStub,
PL_DHashClearEntryStub,
PLDHashTable::MoveEntryStub,
PLDHashTable::ClearEntryStub,
nullptr
};
@ -176,8 +176,8 @@ struct LiteralHashEntry : public PLDHashEntryHdr {
static const PLDHashTableOps gLiteralTableOps = {
LiteralHashEntry::HashKey,
LiteralHashEntry::MatchEntry,
PL_DHashMoveEntryStub,
PL_DHashClearEntryStub,
PLDHashTable::MoveEntryStub,
PLDHashTable::ClearEntryStub,
nullptr
};
@ -210,8 +210,8 @@ struct IntHashEntry : public PLDHashEntryHdr {
static const PLDHashTableOps gIntTableOps = {
IntHashEntry::HashKey,
IntHashEntry::MatchEntry,
PL_DHashMoveEntryStub,
PL_DHashClearEntryStub,
PLDHashTable::MoveEntryStub,
PLDHashTable::ClearEntryStub,
nullptr
};
@ -248,8 +248,8 @@ struct DateHashEntry : public PLDHashEntryHdr {
static const PLDHashTableOps gDateTableOps = {
DateHashEntry::HashKey,
DateHashEntry::MatchEntry,
PL_DHashMoveEntryStub,
PL_DHashClearEntryStub,
PLDHashTable::MoveEntryStub,
PLDHashTable::ClearEntryStub,
nullptr
};
@ -365,8 +365,8 @@ struct BlobHashEntry : public PLDHashEntryHdr {
static const PLDHashTableOps gBlobTableOps = {
BlobHashEntry::HashKey,
BlobHashEntry::MatchEntry,
PL_DHashMoveEntryStub,
PL_DHashClearEntryStub,
PLDHashTable::MoveEntryStub,
PLDHashTable::ClearEntryStub,
nullptr
};

View File

@ -107,9 +107,9 @@ class nsCertOverrideEntry final : public PLDHashEntryHdr
static PLDHashNumber HashKey(KeyTypePointer aKey)
{
// PL_DHashStringKey doesn't use the table parameter, so we can safely
// pass nullptr
return PL_DHashStringKey(nullptr, aKey);
// PLDHashTable::HashStringKey doesn't use the table parameter, so we can
// safely pass nullptr
return PLDHashTable::HashStringKey(nullptr, aKey);
}
enum { ALLOW_MEMMOVE = false };

View File

@ -84,9 +84,9 @@ CompareCacheClearEntry(PLDHashTable *table, PLDHashEntryHdr *hdr)
}
static const PLDHashTableOps gMapOps = {
PL_DHashVoidPtrKeyStub,
PLDHashTable::HashVoidPtrKeyStub,
CompareCacheMatchEntry,
PL_DHashMoveEntryStub,
PLDHashTable::MoveEntryStub,
CompareCacheClearEntry,
CompareCacheInitEntry
};

View File

@ -87,9 +87,9 @@ class nsClientAuthRememberEntry final : public PLDHashEntryHdr
static PLDHashNumber HashKey(KeyTypePointer aKey)
{
// PL_DHashStringKey doesn't use the table parameter, so we can safely
// pass nullptr
return PL_DHashStringKey(nullptr, aKey);
// PLDHashTable::HashStringKey doesn't use the table parameter, so we can
// safely pass nullptr
return PLDHashTable::HashStringKey(nullptr, aKey);
}
enum { ALLOW_MEMMOVE = false };

View File

@ -29,10 +29,10 @@ ObjectSetInitEntry(PLDHashEntryHdr *hdr, const void *key)
}
static const PLDHashTableOps gSetOps = {
PL_DHashVoidPtrKeyStub,
PLDHashTable::HashVoidPtrKeyStub,
ObjectSetMatchEntry,
PL_DHashMoveEntryStub,
PL_DHashClearEntryStub,
PLDHashTable::MoveEntryStub,
PLDHashTable::ClearEntryStub,
ObjectSetInitEntry
};

View File

@ -70,10 +70,10 @@ RequestMapInitEntry(PLDHashEntryHdr *hdr, const void *key)
}
static const PLDHashTableOps gMapOps = {
PL_DHashVoidPtrKeyStub,
PLDHashTable::HashVoidPtrKeyStub,
RequestMapMatchEntry,
PL_DHashMoveEntryStub,
PL_DHashClearEntryStub,
PLDHashTable::MoveEntryStub,
PLDHashTable::ClearEntryStub,
RequestMapInitEntry
};

View File

@ -95,9 +95,9 @@ class nsDefaultComparator <nsDocLoader::nsListenerInfo, nsIWebProgressListener*>
/* static */ const PLDHashTableOps nsDocLoader::sRequestInfoHashOps =
{
PL_DHashVoidPtrKeyStub,
PL_DHashMatchEntryStub,
PL_DHashMoveEntryStub,
PLDHashTable::HashVoidPtrKeyStub,
PLDHashTable::MatchEntryStub,
PLDHashTable::MoveEntryStub,
nsDocLoader::RequestInfoHashClearEntry,
nsDocLoader::RequestInfoHashInitEntry
};

View File

@ -803,10 +803,10 @@ PtrToNodeMatchEntry(PLDHashTable* aTable,
}
static PLDHashTableOps PtrNodeOps = {
PL_DHashVoidPtrKeyStub,
PLDHashTable::HashVoidPtrKeyStub,
PtrToNodeMatchEntry,
PL_DHashMoveEntryStub,
PL_DHashClearEntryStub,
PLDHashTable::MoveEntryStub,
PLDHashTable::ClearEntryStub,
nullptr
};

View File

@ -293,7 +293,7 @@ AtomTableInitEntry(PLDHashEntryHdr* aEntry, const void* aKey)
static const PLDHashTableOps AtomTableOps = {
AtomTableGetHash,
AtomTableMatchKey,
PL_DHashMoveEntryStub,
PLDHashTable::MoveEntryStub,
AtomTableClearEntry,
AtomTableInitEntry
};

View File

@ -51,10 +51,10 @@ ArenaStrdup(const nsAFlatCString& aString, PLArenaPool* aArena)
}
static const struct PLDHashTableOps property_HashTableOps = {
PL_DHashStringKey,
PL_DHashMatchStringKey,
PL_DHashMoveEntryStub,
PL_DHashClearEntryStub,
PLDHashTable::HashStringKey,
PLDHashTable::MatchStringKey,
PLDHashTable::MoveEntryStub,
PLDHashTable::ClearEntryStub,
nullptr,
};

View File

@ -64,7 +64,7 @@ matchNameKeysCaseInsensitive(PLDHashTable*, const PLDHashEntryHdr* aHdr,
}
/*
* caseInsensitiveHashKey is just like PL_DHashStringKey except it
* caseInsensitiveHashKey is just like PLDHashTable::HashStringKey except it
* uses (*s & ~0x20) instead of simply *s. This means that "aFOO" and
* "afoo" and "aFoo" will all hash to the same thing. It also means
* that some strings that aren't case-insensensitively equal will hash
@ -96,8 +96,8 @@ caseInsensitiveStringHashKey(PLDHashTable* aTable, const void* aKey)
static const struct PLDHashTableOps nametable_CaseInsensitiveHashTableOps = {
caseInsensitiveStringHashKey,
matchNameKeysCaseInsensitive,
PL_DHashMoveEntryStub,
PL_DHashClearEntryStub,
PLDHashTable::MoveEntryStub,
PLDHashTable::ClearEntryStub,
nullptr,
};

View File

@ -345,7 +345,7 @@ nsTHashtable<EntryType>::Ops()
{
s_HashKey,
s_MatchEntry,
EntryType::ALLOW_MEMMOVE ? ::PL_DHashMoveEntryStub : s_CopyEntry,
EntryType::ALLOW_MEMMOVE ? PLDHashTable::MoveEntryStub : s_CopyEntry,
s_ClearEntry,
s_InitEntry
};

View File

@ -62,32 +62,32 @@ public:
#endif
PLDHashNumber
PL_DHashStringKey(PLDHashTable* aTable, const void* aKey)
/* static */ PLDHashNumber
PLDHashTable::HashStringKey(PLDHashTable* aTable, const void* aKey)
{
return HashString(static_cast<const char*>(aKey));
}
PLDHashNumber
PL_DHashVoidPtrKeyStub(PLDHashTable* aTable, const void* aKey)
/* static */ PLDHashNumber
PLDHashTable::HashVoidPtrKeyStub(PLDHashTable* aTable, const void* aKey)
{
return (PLDHashNumber)(ptrdiff_t)aKey >> 2;
}
bool
PL_DHashMatchEntryStub(PLDHashTable* aTable,
const PLDHashEntryHdr* aEntry,
const void* aKey)
/* static */ bool
PLDHashTable::MatchEntryStub(PLDHashTable* aTable,
const PLDHashEntryHdr* aEntry,
const void* aKey)
{
const PLDHashEntryStub* stub = (const PLDHashEntryStub*)aEntry;
return stub->key == aKey;
}
bool
PL_DHashMatchStringKey(PLDHashTable* aTable,
const PLDHashEntryHdr* aEntry,
const void* aKey)
/* static */ bool
PLDHashTable::MatchStringKey(PLDHashTable* aTable,
const PLDHashEntryHdr* aEntry,
const void* aKey)
{
const PLDHashEntryStub* stub = (const PLDHashEntryStub*)aEntry;
@ -97,45 +97,32 @@ PL_DHashMatchStringKey(PLDHashTable* aTable,
strcmp((const char*)stub->key, (const char*)aKey) == 0);
}
MOZ_ALWAYS_INLINE void
PLDHashTable::MoveEntryStub(const PLDHashEntryHdr* aFrom,
/* static */ void
PLDHashTable::MoveEntryStub(PLDHashTable* aTable,
const PLDHashEntryHdr* aFrom,
PLDHashEntryHdr* aTo)
{
memcpy(aTo, aFrom, mEntrySize);
memcpy(aTo, aFrom, aTable->mEntrySize);
}
void
PL_DHashMoveEntryStub(PLDHashTable* aTable,
const PLDHashEntryHdr* aFrom,
PLDHashEntryHdr* aTo)
/* static */ void
PLDHashTable::ClearEntryStub(PLDHashTable* aTable, PLDHashEntryHdr* aEntry)
{
aTable->MoveEntryStub(aFrom, aTo);
memset(aEntry, 0, aTable->mEntrySize);
}
MOZ_ALWAYS_INLINE void
PLDHashTable::ClearEntryStub(PLDHashEntryHdr* aEntry)
{
memset(aEntry, 0, mEntrySize);
}
void
PL_DHashClearEntryStub(PLDHashTable* aTable, PLDHashEntryHdr* aEntry)
{
aTable->ClearEntryStub(aEntry);
}
static const PLDHashTableOps stub_ops = {
PL_DHashVoidPtrKeyStub,
PL_DHashMatchEntryStub,
PL_DHashMoveEntryStub,
PL_DHashClearEntryStub,
static const PLDHashTableOps gStubOps = {
PLDHashTable::HashVoidPtrKeyStub,
PLDHashTable::MatchEntryStub,
PLDHashTable::MoveEntryStub,
PLDHashTable::ClearEntryStub,
nullptr
};
const PLDHashTableOps*
PL_DHashGetStubOps(void)
/* static */ const PLDHashTableOps*
PLDHashTable::StubOps()
{
return &stub_ops;
return &gStubOps;
}
static bool

View File

@ -398,9 +398,24 @@ public:
void MarkImmutable();
#endif
void MoveEntryStub(const PLDHashEntryHdr* aFrom, PLDHashEntryHdr* aTo);
// If you use PLDHashEntryStub or a subclass of it as your entry struct, and
// if your entries move via memcpy and clear via memset(0), you can use these
// stub operations.
static const PLDHashTableOps* StubOps();
void ClearEntryStub(PLDHashEntryHdr* aEntry);
// The individual stub operations in StubOps().
static PLDHashNumber HashVoidPtrKeyStub(PLDHashTable* aTable,
const void* aKey);
static bool MatchEntryStub(PLDHashTable* aTable,
const PLDHashEntryHdr* aEntry, const void* aKey);
static void MoveEntryStub(PLDHashTable* aTable, const PLDHashEntryHdr* aFrom,
PLDHashEntryHdr* aTo);
static void ClearEntryStub(PLDHashTable* aTable, PLDHashEntryHdr* aEntry);
// Hash/match operations for tables holding C strings.
static PLDHashNumber HashStringKey(PLDHashTable* aTable, const void* aKey);
static bool MatchStringKey(PLDHashTable* aTable,
const PLDHashEntryHdr* aEntry, const void* aKey);
// This is an iterator for PLDHashtable. Assertions will detect some, but not
// all, mid-iteration table modifications that might invalidate (e.g.
@ -582,42 +597,10 @@ struct PLDHashTableOps
PLDHashInitEntry initEntry;
};
// Default implementations for the above mOps.
PLDHashNumber
PL_DHashStringKey(PLDHashTable* aTable, const void* aKey);
// A minimal entry is a subclass of PLDHashEntryHdr and has void key pointer.
// A minimal entry is a subclass of PLDHashEntryHdr and has a void* key pointer.
struct PLDHashEntryStub : public PLDHashEntryHdr
{
const void* key;
};
PLDHashNumber
PL_DHashVoidPtrKeyStub(PLDHashTable* aTable, const void* aKey);
bool
PL_DHashMatchEntryStub(PLDHashTable* aTable,
const PLDHashEntryHdr* aEntry,
const void* aKey);
bool
PL_DHashMatchStringKey(PLDHashTable* aTable,
const PLDHashEntryHdr* aEntry,
const void* aKey);
void
PL_DHashMoveEntryStub(PLDHashTable* aTable,
const PLDHashEntryHdr* aFrom,
PLDHashEntryHdr* aTo);
void
PL_DHashClearEntryStub(PLDHashTable* aTable, PLDHashEntryHdr* aEntry);
// If you use PLDHashEntryStub or a subclass of it as your entry struct, and
// if your entries move via memcpy and clear via memset(0), you can use these
// stub operations.
const PLDHashTableOps*
PL_DHashGetStubOps(void);
#endif /* pldhash_h___ */

View File

@ -77,7 +77,7 @@ TestCrashyOperation(void (*aCrashyOperation)())
void
InitCapacityOk_InitialLengthTooBig()
{
PLDHashTable t(PL_DHashGetStubOps(), sizeof(PLDHashEntryStub),
PLDHashTable t(PLDHashTable::StubOps(), sizeof(PLDHashEntryStub),
PLDHashTable::kMaxInitialLength + 1);
}
@ -87,7 +87,7 @@ InitCapacityOk_InitialEntryStoreTooBig()
// Try the smallest disallowed power-of-two entry store size, which is 2^32
// bytes (which overflows to 0). (Note that the 2^23 *length* gets converted
// to a 2^24 *capacity*.)
PLDHashTable t(PL_DHashGetStubOps(), (uint32_t)1 << 23, (uint32_t)1 << 8);
PLDHashTable t(PLDHashTable::StubOps(), (uint32_t)1 << 23, (uint32_t)1 << 8);
}
TEST(PLDHashTableTest, InitCapacityOk)
@ -95,12 +95,12 @@ TEST(PLDHashTableTest, InitCapacityOk)
// Try the largest allowed capacity. With kMaxCapacity==1<<26, this
// would allocate (if we added an element) 0.5GB of entry store on 32-bit
// platforms and 1GB on 64-bit platforms.
PLDHashTable t1(PL_DHashGetStubOps(), sizeof(PLDHashEntryStub),
PLDHashTable t1(PLDHashTable::StubOps(), sizeof(PLDHashEntryStub),
PLDHashTable::kMaxInitialLength);
// Try the largest allowed power-of-two entry store size, which is 2^31 bytes
// (Note that the 2^23 *length* gets converted to a 2^24 *capacity*.)
PLDHashTable t2(PL_DHashGetStubOps(), (uint32_t)1 << 23, (uint32_t)1 << 7);
PLDHashTable t2(PLDHashTable::StubOps(), (uint32_t)1 << 23, (uint32_t)1 << 7);
// Try a too-large capacity (which aborts).
TestCrashyOperation(InitCapacityOk_InitialLengthTooBig);
@ -117,7 +117,7 @@ TEST(PLDHashTableTest, InitCapacityOk)
TEST(PLDHashTableTest, LazyStorage)
{
PLDHashTable t(PL_DHashGetStubOps(), sizeof(PLDHashEntryStub));
PLDHashTable t(PLDHashTable::StubOps(), sizeof(PLDHashEntryStub));
// PLDHashTable allocates entry storage lazily. Check that all the non-add
// operations work appropriately when the table is empty and the storage
@ -158,9 +158,9 @@ TrivialInitEntry(PLDHashEntryHdr* aEntry, const void* aKey)
static const PLDHashTableOps trivialOps = {
TrivialHash,
PL_DHashMatchEntryStub,
PL_DHashMoveEntryStub,
PL_DHashClearEntryStub,
PLDHashTable::MatchEntryStub,
PLDHashTable::MoveEntryStub,
PLDHashTable::ClearEntryStub,
TrivialInitEntry
};