Bug 214164 - Reduce nsTHashtable codesize by making sOps a class static. This patch was originally from bug 201034 r=jkeiser :-) and was backed out because GCC 3.3- were stupid. Since we don't support those any more, relanding a=bz

This commit is contained in:
benjamin@smedbergs.us 2007-08-08 07:40:35 -07:00
parent a6fb02c8f1
commit 7052ae973f

View File

@ -90,10 +90,6 @@ PL_DHashStubEnumRemove(PLDHashTable *table,
*
* // HashKey(): calculate the hash number
* static PLDHashNumber HashKey(KeyTypePointer aKey);
*
* // ALLOW_MEMMOVE can we move this class with memmove(), or do we have
* // to use the copy constructor?
* enum { ALLOW_MEMMOVE = PR_(TRUE or FALSE) };
* }</pre>
*
* @see nsInterfaceHashtable
@ -246,11 +242,9 @@ public:
}
protected:
static const PLDHashTableOps sOps;
PLDHashTable mTable;
static const void* PR_CALLBACK s_GetKey(PLDHashTable *table,
PLDHashEntryHdr *entry);
static PLDHashNumber PR_CALLBACK s_HashKey(PLDHashTable *table,
const void *key);
@ -258,10 +252,6 @@ protected:
const PLDHashEntryHdr *entry,
const void *key);
static void PR_CALLBACK s_CopyEntry(PLDHashTable *table,
const PLDHashEntryHdr *from,
PLDHashEntryHdr *to);
static void PR_CALLBACK s_ClearEntry(PLDHashTable *table,
PLDHashEntryHdr *entry);
@ -298,6 +288,20 @@ private:
// template definitions
//
template<class EntryType>
const PLDHashTableOps
nsTHashtable<EntryType>::sOps =
{
::PL_DHashAllocTable,
::PL_DHashFreeTable,
s_HashKey,
s_MatchEntry,
::PL_DHashMoveEntryStub,
s_ClearEntry,
::PL_DHashFinalizeStub,
s_InitEntry
};
template<class EntryType>
nsTHashtable<EntryType>::nsTHashtable()
{
@ -322,23 +326,6 @@ nsTHashtable<EntryType>::Init(PRUint32 initSize)
return PR_TRUE;
}
static PLDHashTableOps sOps =
{
::PL_DHashAllocTable,
::PL_DHashFreeTable,
s_HashKey,
s_MatchEntry,
::PL_DHashMoveEntryStub,
s_ClearEntry,
::PL_DHashFinalizeStub,
s_InitEntry
};
if (!EntryType::ALLOW_MEMMOVE)
{
sOps.moveEntry = s_CopyEntry;
}
if (!PL_DHashTableInit(&mTable, &sOps, nsnull, sizeof(EntryType), initSize))
{
// if failed, reset "flag"
@ -369,20 +356,6 @@ nsTHashtable<EntryType>::s_MatchEntry(PLDHashTable *table,
reinterpret_cast<const KeyTypePointer>(key));
}
template<class EntryType>
void
nsTHashtable<EntryType>::s_CopyEntry(PLDHashTable *table,
const PLDHashEntryHdr *from,
PLDHashEntryHdr *to)
{
EntryType* fromEntry =
const_cast<EntryType*>(reinterpret_cast<const EntryType*>(from));
new(to) EntryType(*fromEntry);
fromEntry->~EntryType();
}
template<class EntryType>
void
nsTHashtable<EntryType>::s_ClearEntry(PLDHashTable *table,