mirror of
https://github.com/mozilla/gecko-dev.git
synced 2025-03-02 14:30:43 +00:00
Bug 1168027 - Use PLDHashTable2 in nsTHashtable. r=froydnj.
The added static_casts will be removed when PLDHashTable and PLDHashTable2 are merged. --HG-- extra : rebase_source : 49dacef8a86adc088610449b6bd2ef9345af5a84
This commit is contained in:
parent
b05edec3d3
commit
6c4f582c73
@ -171,7 +171,7 @@ public:
|
||||
"nsBaseHashtable was not initialized properly.");
|
||||
|
||||
s_EnumReadArgs enumData = { aEnumFunc, aUserArg };
|
||||
return PL_DHashTableEnumerate(const_cast<PLDHashTable*>(&this->mTable),
|
||||
return PL_DHashTableEnumerate(const_cast<PLDHashTable*>(static_cast<const PLDHashTable*>(&this->mTable)),
|
||||
s_EnumReadStub,
|
||||
&enumData);
|
||||
}
|
||||
|
@ -86,8 +86,12 @@ class nsTHashtable
|
||||
public:
|
||||
// Separate constructors instead of default aInitLength parameter since
|
||||
// otherwise the default no-arg constructor isn't found.
|
||||
nsTHashtable() { Init(PL_DHASH_DEFAULT_INITIAL_LENGTH); }
|
||||
explicit nsTHashtable(uint32_t aInitLength) { Init(aInitLength); }
|
||||
nsTHashtable()
|
||||
: mTable(Ops(), sizeof(EntryType), PL_DHASH_DEFAULT_INITIAL_LENGTH)
|
||||
{}
|
||||
explicit nsTHashtable(uint32_t aInitLength)
|
||||
: mTable(Ops(), sizeof(EntryType), aInitLength)
|
||||
{}
|
||||
|
||||
/**
|
||||
* destructor, cleans up and deallocates
|
||||
@ -130,7 +134,7 @@ public:
|
||||
"nsTHashtable was not initialized properly.");
|
||||
|
||||
return static_cast<EntryType*>(
|
||||
PL_DHashTableSearch(const_cast<PLDHashTable*>(&mTable),
|
||||
PL_DHashTableSearch(const_cast<PLDHashTable*>(static_cast<const PLDHashTable*>(&mTable)),
|
||||
EntryType::KeyToPointer(aKey)));
|
||||
}
|
||||
|
||||
@ -324,7 +328,7 @@ public:
|
||||
#endif
|
||||
|
||||
protected:
|
||||
PLDHashTable mTable;
|
||||
PLDHashTable2 mTable;
|
||||
|
||||
static const void* s_GetKey(PLDHashTable* aTable, PLDHashEntryHdr* aEntry);
|
||||
|
||||
@ -378,10 +382,9 @@ private:
|
||||
nsTHashtable(nsTHashtable<EntryType>& aToCopy) = delete;
|
||||
|
||||
/**
|
||||
* Initialize the table.
|
||||
* @param aInitLength the initial number of buckets in the hashtable
|
||||
* Gets the table's ops.
|
||||
*/
|
||||
void Init(uint32_t aInitLength);
|
||||
static const PLDHashTableOps* Ops();
|
||||
|
||||
/**
|
||||
* An implementation of SizeOfEntryExcludingThisFun that calls SizeOfExcludingThis()
|
||||
@ -411,15 +414,15 @@ nsTHashtable<EntryType>::nsTHashtable(nsTHashtable<EntryType>&& aOther)
|
||||
template<class EntryType>
|
||||
nsTHashtable<EntryType>::~nsTHashtable()
|
||||
{
|
||||
if (mTable.IsInitialized()) {
|
||||
PL_DHashTableFinish(&mTable);
|
||||
}
|
||||
}
|
||||
|
||||
template<class EntryType>
|
||||
void
|
||||
nsTHashtable<EntryType>::Init(uint32_t aInitLength)
|
||||
/* static */ const PLDHashTableOps*
|
||||
nsTHashtable<EntryType>::Ops()
|
||||
{
|
||||
// If this variable is a global variable, we get strange start-up failures on
|
||||
// WindowsCrtPatch.h (see bug 1166598 comment 20). But putting it inside a
|
||||
// function avoids that problem.
|
||||
static const PLDHashTableOps sOps =
|
||||
{
|
||||
s_HashKey,
|
||||
@ -428,8 +431,7 @@ nsTHashtable<EntryType>::Init(uint32_t aInitLength)
|
||||
s_ClearEntry,
|
||||
s_InitEntry
|
||||
};
|
||||
|
||||
PL_DHashTableInit(&mTable, &sOps, sizeof(EntryType), aInitLength);
|
||||
return &sOps;
|
||||
}
|
||||
|
||||
// static
|
||||
|
Loading…
x
Reference in New Issue
Block a user