bug 200709 remove dynamic linking of nsTHashtable and family. r=jkeiser sr=alecf

This commit is contained in:
bsmedberg%covad.net 2005-08-11 19:43:01 +00:00
Родитель e3af36ec5c
Коммит 8167a5c5f4
6 изменённых файлов: 404 добавлений и 90 удалений

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

@ -40,7 +40,8 @@
#include "nsTHashtable.h"
#include NEW_H
typedef struct PRRWLock PRRWLock;
#include "prrwlock.h"
#include "nsDebug.h"
template<class KeyClass,class DataType,class UserDataType>
class nsBaseHashtable; // forward declaration
@ -183,8 +184,180 @@ protected:
void *arg);
};
#ifndef HAVE_CPP_EXTERN_INSTANTIATION
#include "nsBaseHashtableImpl.h"
#endif
//
// nsBaseHashtableET definitions
//
template<class KeyClass,class DataType>
nsBaseHashtableET<KeyClass,DataType>::nsBaseHashtableET(KeyTypePointer aKey) :
KeyClass(aKey)
{ }
template<class KeyClass,class DataType>
nsBaseHashtableET<KeyClass,DataType>::nsBaseHashtableET
(const nsBaseHashtableET<KeyClass,DataType>& toCopy) :
KeyClass(toCopy),
mData(toCopy.mData)
{ }
template<class KeyClass,class DataType>
nsBaseHashtableET<KeyClass,DataType>::~nsBaseHashtableET()
{ }
//
// nsBaseHashtable definitions
//
template<class KeyClass,class DataType,class UserDataType>
nsBaseHashtable<KeyClass,DataType,UserDataType>::nsBaseHashtable()
{ }
template<class KeyClass,class DataType,class UserDataType>
nsBaseHashtable<KeyClass,DataType,UserDataType>::~nsBaseHashtable()
{
if (mLock)
PR_DestroyRWLock(mLock);
}
template<class KeyClass,class DataType,class UserDataType>
PRBool
nsBaseHashtable<KeyClass,DataType,UserDataType>::Init(PRUint32 initSize,
PRBool threadSafe)
{
if (!nsTHashtable<EntryType>::Init(initSize))
return PR_FALSE;
if (!threadSafe)
{
mLock = nsnull;
return PR_TRUE;
}
mLock = PR_NewRWLock(PR_RWLOCK_RANK_NONE, "nsBaseHashtable");
NS_WARN_IF_FALSE(mLock, "Error creating lock during nsBaseHashtable::Init()");
if (!mLock)
return PR_FALSE;
return PR_TRUE;
}
template<class KeyClass,class DataType,class UserDataType>
PRBool
nsBaseHashtable<KeyClass,DataType,UserDataType>::Get(KeyType aKey,
UserDataType* pData) const
{
if (mLock)
PR_RWLock_Rlock(mLock);
EntryType* ent = GetEntry(KeyClass::KeyToPointer(aKey));
if (ent)
{
if (pData)
*pData = ent->mData;
if (mLock)
PR_RWLock_Unlock(mLock);
return PR_TRUE;
}
if (mLock)
PR_RWLock_Unlock(mLock);
return PR_FALSE;
}
template<class KeyClass,class DataType,class UserDataType>
PRBool
nsBaseHashtable<KeyClass,DataType,UserDataType>::Put(KeyType aKey,
UserDataType aData)
{
if (mLock)
PR_RWLock_Wlock(mLock);
EntryType* ent = PutEntry(KeyClass::KeyToPointer(aKey));
if (!ent)
{
if (mLock)
PR_RWLock_Unlock(mLock);
return PR_FALSE;
}
ent->mData = aData;
if (mLock)
PR_RWLock_Unlock(mLock);
return PR_TRUE;
}
template<class KeyClass,class DataType,class UserDataType>
void
nsBaseHashtable<KeyClass,DataType,UserDataType>::Remove(KeyType aKey)
{
if (mLock)
PR_RWLock_Wlock(mLock);
RemoveEntry(KeyClass::KeyToPointer(aKey));
if (mLock)
PR_RWLock_Unlock(mLock);
}
template<class KeyClass,class DataType,class UserDataType>
void
nsBaseHashtable<KeyClass,DataType,UserDataType>::EnumerateRead
(EnumReadFunction fEnumCall, void* userArg) const
{
NS_ASSERTION(mTable.entrySize,
"nsBaseHashtable was not initialized properly.");
if (mLock)
PR_RWLock_Rlock(mLock);
s_EnumReadArgs enumData = { fEnumCall, userArg };
PL_DHashTableEnumerate(NS_CONST_CAST(PLDHashTable*,&mTable),
s_EnumStub,
&enumData);
if (mLock)
PR_RWLock_Unlock(mLock);
}
template<class KeyClass,class DataType,class UserDataType>
void nsBaseHashtable<KeyClass,DataType,UserDataType>::Clear()
{
if (mLock)
PR_RWLock_Wlock(mLock);
nsTHashtable<EntryType>::Clear();
if (mLock)
PR_RWLock_Unlock(mLock);
}
template<class KeyClass,class DataType,class UserDataType>
PLDHashOperator
nsBaseHashtable<KeyClass,DataType,UserDataType>::s_EnumReadStub
(PLDHashTable *table, PLDHashEntryHdr *hdr, PRUint32 number, void* arg)
{
EntryType* ent = NS_STATIC_CAST(EntryType*, hdr);
s_EnumReadArgs* eargs = (s_EnumReadArgs*) arg;
PLDHashOperator res = (eargs->func)(ent->GetKey(), ent->mData, eargs->userArg);
NS_ASSERTION( !(res & PL_DHASH_REMOVE ),
"PL_DHASH_REMOVE return during const enumeration; ignoring.");
if (res & PL_DHASH_STOP)
return PL_DHASH_STOP;
return PL_DHASH_NEXT;
}
#endif // nsBaseHashtable_h__

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

@ -74,14 +74,9 @@ public:
PRBool Get(KeyType aKey, UserDataType* pData) const;
};
/*
* this class doesn't have any predefined instances; implementations are
* included here
*/
#ifndef nsTHashtableImpl_h__
#include "nsTHashtableImpl.h"
#endif
//
// nsClassHashtable definitions
//
template<class KeyClass,class T>
PRBool

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

@ -54,25 +54,4 @@ class nsDataHashtable :
public nsBaseHashtable<KeyClass,DataType,DataType>
{ };
/**
* declare shared-linkage for common usages of nsDataHashtable.
*
* To avoid including this code in multiple translation units, common usages
* are predeclared with external linkage. To add to this list, include the
* declarations here, definitions in nsTHashtable.cpp and dlldeps.cpp . This
* only works if the configure-test HAVE_CPP_EXTERN_INSTANTIATION succeeds.
*/
#ifndef HAVE_CPP_EXTERN_INSTANTIATION
#include "nsBaseHashtableImpl.h"
#else
#ifndef NO_THASHTABLE_EXTERN_DECL
extern template class NS_COM nsBaseHashtableET<nsUint32HashKey,PRInt32>;
extern template class NS_COM nsTHashtable< nsBaseHashtableET<nsUint32HashKey,PRInt32> >;
extern template class NS_COM nsBaseHashtable<nsUint32HashKey,PRInt32,PRInt32>;
extern template class NS_COM nsDataHashtable<nsUint32HashKey,PRInt32>;
#else
#include "nsBaseHashtableImpl.h"
#endif
#endif
#endif // nsDataHashtable_h__

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

@ -75,25 +75,46 @@ public:
PRBool Get(KeyType aKey, UserDataType* pData) const;
};
/**
* declare shared-linkage for common usages of nsDataHashtable.
*
* To avoid including this code in multiple translation units, common usages
* are predeclared with external linkage. To add to this list, include the
* declarations here, definitions in nsTHashtable.cpp and dlldeps.cpp . This
* only works if the configure-test HAVE_CPP_EXTERN_INSTANTIATION succeeds.
*/
#ifndef HAVE_CPP_EXTERN_INSTANTIATION
#include "nsInterfaceHashtableImpl.h"
#else
#ifndef NO_THASHTABLE_EXTERN_DECL
extern template class NS_COM nsBaseHashtableET<nsStringHashKey, nsCOMPtr<nsISupports> >;
extern template class NS_COM nsTHashtable< nsBaseHashtableET<nsStringHashKey,nsCOMPtr<nsISupports> > >;
extern template class NS_COM nsBaseHashtable<nsStringHashKey, nsCOMPtr<nsISupports>, nsISupports*>;
extern template class NS_COM nsInterfaceHashtable<nsStringHashKey, nsISupports>;
#else
#include "nsInterfaceHashtableImpl.h"
#endif
#endif
//
// nsInterfaceHashtable definitions
//
template<class KeyClass,class Interface>
PRBool
nsInterfaceHashtable<KeyClass,Interface>::Get
(KeyType aKey, UserDataType* pInterface) const
{
if (mLock)
PR_RWLock_Rlock(mLock);
typename nsBaseHashtable<KeyClass, nsCOMPtr<Interface>, Interface*>::EntryType* ent =
GetEntry(KeyClass::KeyToPointer(aKey));
if (ent)
{
if (pInterface)
{
*pInterface = ent->mData;
NS_IF_ADDREF(*pInterface);
}
if (mLock)
PR_RWLock_Unlock(mLock);
return PR_TRUE;
}
// if the key doesn't exist, set *pInterface to null
// so that it is a valid XPCOM getter
if (pInterface)
*pInterface = nsnull;
if (mLock)
PR_RWLock_Unlock(mLock);
return PR_FALSE;
}
#endif // nsInterfaceHashtable_h__

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

@ -35,16 +35,11 @@
*
* ***** END LICENSE BLOCK ***** */
#define NO_THASHTABLE_EXTERN_DECL
#include "nsTHashtable.h"
#include "nsTHashtableImpl.h"
#include "nsInterfaceHashtable.h"
#include "nsInterfaceHashtableImpl.h"
#include "nsDataHashtable.h"
#include "nsHashKeys.h"
PLDHashOperator PL_DHashStubEnumRemove(PLDHashTable *table,
PR_IMPLEMENT(PLDHashOperator)
PL_DHashStubEnumRemove(PLDHashTable *table,
PLDHashEntryHdr *entry,
PRUint32 ordinal,
void *userarg)
@ -65,18 +60,3 @@ PRUint32 nsIDHashKey::HashKey(const nsID* id)
return h;
}
// explicit instantiation of templates
#ifdef HAVE_CPP_EXTERN_INSTANTIATION
/* instantiate common nsInterfaceHashtable uses */
template class NS_EXPORT nsBaseHashtableET<nsStringHashKey,nsCOMPtr<nsISupports> >;
template class NS_EXPORT nsTHashtable< nsBaseHashtableET<nsStringHashKey,nsCOMPtr<nsISupports> > >;
template class NS_EXPORT nsBaseHashtable<nsStringHashKey,nsCOMPtr<nsISupports>,nsISupports*>;
template class NS_EXPORT nsInterfaceHashtable<nsStringHashKey,nsISupports>;
/* instantiate common nsDataHashtable uses */
template class NS_EXPORT nsBaseHashtableET<nsUint32HashKey,PRInt32>;
template class NS_EXPORT nsTHashtable< nsBaseHashtableET<nsUint32HashKey,PRInt32> >;
template class NS_EXPORT nsBaseHashtable<nsUint32HashKey,PRInt32,PRInt32>;
template class NS_EXPORT nsDataHashtable<nsUint32HashKey,PRInt32>;
#endif // HAVE_CPP_EXTERN_INSTANTIATION

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

@ -40,10 +40,7 @@
#include "nscore.h"
#include "pldhash.h"
#ifdef _MSC_VER
#pragma warning( disable: 4231 ) // 'extern template' nonstandard C++ extension
#endif
#include "nsDebug.h"
/**
* a base class for templated hashtables.
@ -225,17 +222,186 @@ protected:
};
// helper function for Reset()
PLDHashOperator PL_DHashStubEnumRemove(PLDHashTable *table,
PLDHashEntryHdr *entry,
PRUint32 ordinal,
void *userArg);
PR_EXTERN(PLDHashOperator)
PL_DHashStubEnumRemove(PLDHashTable *table,
PLDHashEntryHdr *entry,
PRUint32 ordinal,
void *userArg);
/**
* if we can't declare external linkage for templates, we need to include the
* implementation header.
*/
#ifndef HAVE_CPP_EXTERN_INSTANTIATION
#include "nsTHashtableImpl.h"
#endif
//
// template definitions
//
template<class EntryType>
nsTHashtable<EntryType>::nsTHashtable()
{
// entrySize is our "I'm initialized" indicator
mTable.entrySize = 0;
}
template<class EntryType>
nsTHashtable<EntryType>::~nsTHashtable()
{
if (mTable.entrySize)
PL_DHashTableFinish(&mTable);
}
template<class EntryType>
PRBool
nsTHashtable<EntryType>::Init(PRUint32 initSize)
{
if (mTable.entrySize)
{
NS_ERROR("nsTHashtable::Init() should not be called twice.");
return PR_FALSE;
}
if (!PL_DHashTableInit(&mTable, &sOps, nsnull, sizeof(EntryType), initSize))
{
// if failed, reset "flag"
mTable.entrySize = 0;
return PR_FALSE;
}
return PR_TRUE;
}
template<class EntryType>
EntryType*
nsTHashtable<EntryType>::GetEntry(KeyTypePointer aKey) const
{
NS_ASSERTION(mTable.entrySize, "nsTHashtable was not initialized properly.");
return NS_REINTERPRET_CAST(EntryType*,
PL_DHashTableOperate(
NS_CONST_CAST(PLDHashTable*,&mTable),
aKey,
PL_DHASH_LOOKUP));
}
template<class EntryType>
EntryType*
nsTHashtable<EntryType>::PutEntry(KeyTypePointer aKey)
{
NS_ASSERTION(mTable.entrySize, "nsTHashtable was not initialized properly.");
return (EntryType*) PL_DHashTableOperate(&mTable, aKey, PL_DHASH_ADD);
}
template<class EntryType>
void
nsTHashtable<EntryType>::RemoveEntry(KeyTypePointer aKey)
{
NS_ASSERTION(mTable.entrySize, "nsTHashtable was not initialized properly.");
PL_DHashTableOperate(&mTable, aKey, PL_DHASH_REMOVE);
return;
}
template<class EntryType>
PRUint32
nsTHashtable<EntryType>::EnumerateEntries(Enumerator enumFunc, void* userArg)
{
NS_ASSERTION(mTable.entrySize, "nsTHashtable was not initialized properly.");
s_EnumArgs args = { enumFunc, userArg };
return PL_DHashTableEnumerate(&mTable, s_EnumStub, &args);
}
template<class EntryType>
void
nsTHashtable<EntryType>::Clear()
{
NS_ASSERTION(mTable.entrySize, "nsTHashtable was not initialized properly.");
PL_DHashTableEnumerate(&mTable, PL_DHashStubEnumRemove, nsnull);
}
// static definitions
template<class EntryType>
PLDHashTableOps
nsTHashtable<EntryType>::sOps =
{
::PL_DHashAllocTable,
::PL_DHashFreeTable,
s_GetKey,
s_HashKey,
s_MatchEntry,
EntryType::AllowMemMove() ? ::PL_DHashMoveEntryStub : s_CopyEntry,
s_ClearEntry,
::PL_DHashFinalizeStub,
s_InitEntry
};
template<class EntryType>
const void*
nsTHashtable<EntryType>::s_GetKey(PLDHashTable *table,
PLDHashEntryHdr *entry)
{
return ((EntryType*) entry)->GetKeyPointer();
}
template<class EntryType>
PLDHashNumber
nsTHashtable<EntryType>::s_HashKey(PLDHashTable *table,
const void *key)
{
return EntryType::HashKey(NS_REINTERPRET_CAST(const KeyTypePointer, key));
}
template<class EntryType>
PRBool
nsTHashtable<EntryType>::s_MatchEntry(PLDHashTable *table,
const PLDHashEntryHdr *entry,
const void *key)
{
return ((const EntryType*) entry)->KeyEquals(
NS_REINTERPRET_CAST(const KeyTypePointer, key));
}
template<class EntryType>
void
nsTHashtable<EntryType>::s_CopyEntry(PLDHashTable *table,
const PLDHashEntryHdr *from,
PLDHashEntryHdr *to)
{
new(to) EntryType(* NS_REINTERPRET_CAST(const EntryType*,from));
NS_CONST_CAST(EntryType*,NS_REINTERPRET_CAST(const EntryType*,from))->~EntryType();
}
template<class EntryType>
void
nsTHashtable<EntryType>::s_ClearEntry(PLDHashTable *table,
PLDHashEntryHdr *entry)
{
NS_REINTERPRET_CAST(EntryType*,entry)->~EntryType();
}
template<class EntryType>
void
nsTHashtable<EntryType>::s_InitEntry(PLDHashTable *table,
PLDHashEntryHdr *entry,
const void *key)
{
new(entry) EntryType(NS_REINTERPRET_CAST(KeyTypePointer,key));
}
template<class EntryType>
PLDHashOperator
nsTHashtable<EntryType>::s_EnumStub(PLDHashTable *table,
PLDHashEntryHdr *entry,
PRUint32 number,
void *arg)
{
// dereferences the function-pointer to the user's enumeration function
return (* NS_REINTERPRET_CAST(s_EnumArgs*,arg)->userFunc)(
NS_REINTERPRET_CAST(EntryType*,entry),
NS_REINTERPRET_CAST(s_EnumArgs*,arg)->userArg);
}
#endif // nsTHashtable_h__