mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-12-02 01:48:05 +00:00
Bug 1181445 (part 6) - Use nsBaseHashTable::Iterator in xpcom/components/. r=froydnj.
Note that enumfunc_pentries and persistent_userstruct are unused, and so could be removed. --HG-- extra : rebase_source : 57ae41aa2e7d514dc8f3f3d79d3d1946a407c4ac
This commit is contained in:
parent
240d180d7f
commit
d13b0d1848
@ -321,34 +321,6 @@ CategoryNode::SizeOfExcludingThis(MallocSizeOf aMallocSizeOf)
|
||||
return mTable.SizeOfExcludingThis(nullptr, aMallocSizeOf);
|
||||
}
|
||||
|
||||
struct persistent_userstruct
|
||||
{
|
||||
PRFileDesc* fd;
|
||||
const char* categoryName;
|
||||
bool success;
|
||||
};
|
||||
|
||||
PLDHashOperator
|
||||
enumfunc_pentries(CategoryLeaf* aLeaf, void* aUserArg)
|
||||
{
|
||||
persistent_userstruct* args = static_cast<persistent_userstruct*>(aUserArg);
|
||||
|
||||
PLDHashOperator status = PL_DHASH_NEXT;
|
||||
|
||||
if (aLeaf->value) {
|
||||
if (PR_fprintf(args->fd,
|
||||
"%s,%s,%s\n",
|
||||
args->categoryName,
|
||||
aLeaf->GetKey(),
|
||||
aLeaf->value) == (uint32_t)-1) {
|
||||
args->success = false;
|
||||
status = PL_DHASH_STOP;
|
||||
}
|
||||
}
|
||||
|
||||
return status;
|
||||
}
|
||||
|
||||
//
|
||||
// CategoryEnumerator class
|
||||
//
|
||||
@ -359,12 +331,6 @@ class CategoryEnumerator
|
||||
public:
|
||||
static CategoryEnumerator* Create(nsClassHashtable<nsDepCharHashKey,
|
||||
CategoryNode>& aTable);
|
||||
|
||||
private:
|
||||
static PLDHashOperator
|
||||
enumfunc_createenumerator(const char* aStr,
|
||||
CategoryNode* aNode,
|
||||
void* aUserArg);
|
||||
};
|
||||
|
||||
CategoryEnumerator*
|
||||
@ -382,24 +348,16 @@ CategoryEnumerator::Create(nsClassHashtable<nsDepCharHashKey, CategoryNode>&
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
aTable.EnumerateRead(enumfunc_createenumerator, enumObj);
|
||||
|
||||
return enumObj;
|
||||
}
|
||||
|
||||
PLDHashOperator
|
||||
CategoryEnumerator::enumfunc_createenumerator(const char* aStr,
|
||||
CategoryNode* aNode,
|
||||
void* aUserArg)
|
||||
{
|
||||
CategoryEnumerator* mythis = static_cast<CategoryEnumerator*>(aUserArg);
|
||||
|
||||
// if a category has no entries, we pretend it doesn't exist
|
||||
if (aNode->Count()) {
|
||||
mythis->mArray[mythis->mCount++] = aStr;
|
||||
for (auto iter = aTable.Iter(); !iter.Done(); iter.Next()) {
|
||||
// if a category has no entries, we pretend it doesn't exist
|
||||
CategoryNode* aNode = iter.GetUserData();
|
||||
if (aNode->Count()) {
|
||||
const char* str = iter.GetKey();
|
||||
enumObj->mArray[enumObj->mCount++] = str;
|
||||
}
|
||||
}
|
||||
|
||||
return PL_DHASH_NEXT;
|
||||
return enumObj;
|
||||
}
|
||||
|
||||
|
||||
|
@ -1237,16 +1237,6 @@ nsComponentManagerImpl::CreateInstanceByContractID(const char* aContractID,
|
||||
return rv;
|
||||
}
|
||||
|
||||
static PLDHashOperator
|
||||
FreeFactoryEntries(const nsID& aCID,
|
||||
nsFactoryEntry* aEntry,
|
||||
void* aArg)
|
||||
{
|
||||
aEntry->mFactory = nullptr;
|
||||
aEntry->mServiceObject = nullptr;
|
||||
return PL_DHASH_NEXT;
|
||||
}
|
||||
|
||||
nsresult
|
||||
nsComponentManagerImpl::FreeServices()
|
||||
{
|
||||
@ -1257,7 +1247,12 @@ nsComponentManagerImpl::FreeServices()
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
|
||||
mFactories.EnumerateRead(FreeFactoryEntries, nullptr);
|
||||
for (auto iter = mFactories.Iter(); !iter.Done(); iter.Next()) {
|
||||
nsFactoryEntry* entry = iter.GetUserData();
|
||||
entry->mFactory = nullptr;
|
||||
entry->mServiceObject = nullptr;
|
||||
}
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
@ -1764,40 +1759,27 @@ nsComponentManagerImpl::IsContractIDRegistered(const char* aClass,
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
static PLDHashOperator
|
||||
EnumerateCIDHelper(const nsID& aId, nsFactoryEntry* aEntry, void* aClosure)
|
||||
{
|
||||
nsCOMArray<nsISupports>* array =
|
||||
static_cast<nsCOMArray<nsISupports>*>(aClosure);
|
||||
nsCOMPtr<nsISupportsID> wrapper = new nsSupportsIDImpl();
|
||||
wrapper->SetData(&aId);
|
||||
array->AppendObject(wrapper);
|
||||
return PL_DHASH_NEXT;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsComponentManagerImpl::EnumerateCIDs(nsISimpleEnumerator** aEnumerator)
|
||||
{
|
||||
nsCOMArray<nsISupports> array;
|
||||
mFactories.EnumerateRead(EnumerateCIDHelper, &array);
|
||||
|
||||
for (auto iter = mFactories.Iter(); !iter.Done(); iter.Next()) {
|
||||
const nsID& id = iter.GetKey();
|
||||
nsCOMPtr<nsISupportsID> wrapper = new nsSupportsIDImpl();
|
||||
wrapper->SetData(&id);
|
||||
array.AppendObject(wrapper);
|
||||
}
|
||||
return NS_NewArrayEnumerator(aEnumerator, array);
|
||||
}
|
||||
|
||||
static PLDHashOperator
|
||||
EnumerateContractsHelper(const nsACString& aContract, nsFactoryEntry* aEntry,
|
||||
void* aClosure)
|
||||
{
|
||||
nsTArray<nsCString>* array = static_cast<nsTArray<nsCString>*>(aClosure);
|
||||
array->AppendElement(aContract);
|
||||
return PL_DHASH_NEXT;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsComponentManagerImpl::EnumerateContractIDs(nsISimpleEnumerator** aEnumerator)
|
||||
{
|
||||
nsTArray<nsCString>* array = new nsTArray<nsCString>;
|
||||
mContractIDs.EnumerateRead(EnumerateContractsHelper, array);
|
||||
for (auto iter = mContractIDs.Iter(); !iter.Done(); iter.Next()) {
|
||||
const nsACString& contract = iter.GetKey();
|
||||
array->AppendElement(contract);
|
||||
}
|
||||
|
||||
nsCOMPtr<nsIUTF8StringEnumerator> e;
|
||||
nsresult rv = NS_NewAdoptingUTF8StringEnumerator(getter_AddRefs(e), array);
|
||||
|
@ -191,50 +191,44 @@ nsNativeModuleLoader::LoadModule(FileLocation& aFile)
|
||||
return data.mModule;
|
||||
}
|
||||
|
||||
PLDHashOperator
|
||||
nsNativeModuleLoader::ReleaserFunc(nsIHashable* aHashedFile,
|
||||
NativeLoadData& aLoadData, void*)
|
||||
{
|
||||
aLoadData.mModule = nullptr;
|
||||
return PL_DHASH_NEXT;
|
||||
}
|
||||
|
||||
PLDHashOperator
|
||||
nsNativeModuleLoader::UnloaderFunc(nsIHashable* aHashedFile,
|
||||
NativeLoadData& aLoadData, void*)
|
||||
{
|
||||
if (MOZ_LOG_TEST(GetNativeModuleLoaderLog(), LogLevel::Debug)) {
|
||||
nsCOMPtr<nsIFile> file(do_QueryInterface(aHashedFile));
|
||||
|
||||
nsAutoCString filePath;
|
||||
file->GetNativePath(filePath);
|
||||
|
||||
LOG(LogLevel::Debug,
|
||||
("nsNativeModuleLoader::UnloaderFunc(\"%s\")", filePath.get()));
|
||||
}
|
||||
|
||||
#ifdef NS_BUILD_REFCNT_LOGGING
|
||||
nsTraceRefcnt::SetActivityIsLegal(false);
|
||||
#endif
|
||||
|
||||
#if 0
|
||||
// XXXbsmedberg: do this as soon as the static-destructor crash(es)
|
||||
// are fixed
|
||||
PRStatus ret = PR_UnloadLibrary(aLoadData.mLibrary);
|
||||
NS_ASSERTION(ret == PR_SUCCESS, "Failed to unload library");
|
||||
#endif
|
||||
|
||||
#ifdef NS_BUILD_REFCNT_LOGGING
|
||||
nsTraceRefcnt::SetActivityIsLegal(true);
|
||||
#endif
|
||||
|
||||
return PL_DHASH_REMOVE;
|
||||
}
|
||||
|
||||
void
|
||||
nsNativeModuleLoader::UnloadLibraries()
|
||||
{
|
||||
MOZ_ASSERT(NS_IsMainThread(), "Shutdown not on main thread?");
|
||||
mLibraries.Enumerate(ReleaserFunc, nullptr);
|
||||
mLibraries.Enumerate(UnloaderFunc, nullptr);
|
||||
|
||||
for (auto iter = mLibraries.Iter(); !iter.Done(); iter.Next()) {
|
||||
NativeLoadData& loadData = iter.GetData();
|
||||
loadData.mModule = nullptr;
|
||||
}
|
||||
|
||||
for (auto iter = mLibraries.Iter(); !iter.Done(); iter.Next()) {
|
||||
if (MOZ_LOG_TEST(GetNativeModuleLoaderLog(), LogLevel::Debug)) {
|
||||
nsIHashable* hashedFile = iter.GetKey();
|
||||
nsCOMPtr<nsIFile> file(do_QueryInterface(hashedFile));
|
||||
|
||||
nsAutoCString filePath;
|
||||
file->GetNativePath(filePath);
|
||||
|
||||
LOG(LogLevel::Debug,
|
||||
("nsNativeModuleLoader::UnloaderFunc(\"%s\")", filePath.get()));
|
||||
}
|
||||
|
||||
#ifdef NS_BUILD_REFCNT_LOGGING
|
||||
nsTraceRefcnt::SetActivityIsLegal(false);
|
||||
#endif
|
||||
|
||||
#if 0
|
||||
// XXXbsmedberg: do this as soon as the static-destructor crash(es)
|
||||
// are fixed
|
||||
NativeLoadData& loadData = iter.GetData();
|
||||
PRStatus ret = PR_UnloadLibrary(loadData.mLibrary);
|
||||
NS_ASSERTION(ret == PR_SUCCESS, "Failed to unload library");
|
||||
#endif
|
||||
|
||||
#ifdef NS_BUILD_REFCNT_LOGGING
|
||||
nsTraceRefcnt::SetActivityIsLegal(true);
|
||||
#endif
|
||||
|
||||
iter.Remove();
|
||||
}
|
||||
}
|
||||
|
@ -33,12 +33,6 @@ private:
|
||||
PRLibrary* mLibrary;
|
||||
};
|
||||
|
||||
static PLDHashOperator
|
||||
ReleaserFunc(nsIHashable* aHashedFile, NativeLoadData& aLoadData, void*);
|
||||
|
||||
static PLDHashOperator
|
||||
UnloaderFunc(nsIHashable* aHashedFile, NativeLoadData& aLoadData, void*);
|
||||
|
||||
nsDataHashtable<nsHashableHashKey, NativeLoadData> mLibraries;
|
||||
};
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user