Bug 1376483 - Use Lookup instead of Get+Remove, and LookupForAdd instead of Get+Put, to avoid unnecessary hashtable lookups. r=froydnj
MozReview-Commit-ID: Lgq12HL5gnd
This commit is contained in:
@@ -482,8 +482,8 @@ nsComponentManagerImpl::RegisterCIDEntryLocked(
|
||||
return;
|
||||
}
|
||||
|
||||
nsFactoryEntry* f = mFactories.Get(*aEntry->cid);
|
||||
if (f) {
|
||||
if (auto entry = mFactories.LookupForAdd(*aEntry->cid)) {
|
||||
nsFactoryEntry* f = entry.Data();
|
||||
NS_WARNING("Re-registering a CID?");
|
||||
|
||||
char idstr[NSID_LENGTH];
|
||||
@@ -500,11 +500,9 @@ nsComponentManagerImpl::RegisterCIDEntryLocked(
|
||||
aModule->Description().get(),
|
||||
idstr,
|
||||
existing.get());
|
||||
return;
|
||||
} else {
|
||||
entry.OrInsert([aEntry, aModule] () { return new nsFactoryEntry(aEntry, aModule); });
|
||||
}
|
||||
|
||||
f = new nsFactoryEntry(aEntry, aModule);
|
||||
mFactories.Put(*aEntry->cid, f);
|
||||
}
|
||||
|
||||
void
|
||||
@@ -654,8 +652,9 @@ nsComponentManagerImpl::ManifestComponent(ManifestProcessingContext& aCx,
|
||||
fl.GetURIString(hash);
|
||||
|
||||
MutexLock lock(mLock);
|
||||
nsFactoryEntry* f = mFactories.Get(cid);
|
||||
if (f) {
|
||||
auto entry = mFactories.LookupForAdd(cid);
|
||||
if (entry) {
|
||||
nsFactoryEntry* f = entry.Data();
|
||||
char idstr[NSID_LENGTH];
|
||||
cid.ToProvidedString(idstr);
|
||||
|
||||
@@ -691,8 +690,7 @@ nsComponentManagerImpl::ManifestComponent(ManifestProcessingContext& aCx,
|
||||
auto* e = new (KnownNotNull, place) mozilla::Module::CIDEntry();
|
||||
e->cid = permanentCID;
|
||||
|
||||
f = new nsFactoryEntry(e, km);
|
||||
mFactories.Put(cid, f);
|
||||
entry.OrInsert([e, km] () { return new nsFactoryEntry(e, km); });
|
||||
}
|
||||
|
||||
void
|
||||
@@ -1532,17 +1530,15 @@ nsComponentManagerImpl::RegisterFactory(const nsCID& aClass,
|
||||
nsAutoPtr<nsFactoryEntry> f(new nsFactoryEntry(aClass, aFactory));
|
||||
|
||||
SafeMutexAutoLock lock(mLock);
|
||||
nsFactoryEntry* oldf = mFactories.Get(aClass);
|
||||
if (oldf) {
|
||||
if (auto entry = mFactories.LookupForAdd(aClass)) {
|
||||
return NS_ERROR_FACTORY_EXISTS;
|
||||
} else {
|
||||
if (aContractID) {
|
||||
mContractIDs.Put(nsDependentCString(aContractID), f);
|
||||
}
|
||||
entry.OrInsert([&f] () { return f.forget(); });
|
||||
}
|
||||
|
||||
if (aContractID) {
|
||||
mContractIDs.Put(nsDependentCString(aContractID), f);
|
||||
}
|
||||
|
||||
mFactories.Put(aClass, f.forget());
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
@@ -1557,12 +1553,13 @@ nsComponentManagerImpl::UnregisterFactory(const nsCID& aClass,
|
||||
|
||||
{
|
||||
SafeMutexAutoLock lock(mLock);
|
||||
nsFactoryEntry* f = mFactories.Get(aClass);
|
||||
auto entry = mFactories.Lookup(aClass);
|
||||
nsFactoryEntry* f = entry ? entry.Data() : nullptr;
|
||||
if (!f || f->mFactory != aFactory) {
|
||||
return NS_ERROR_FACTORY_NOT_REGISTERED;
|
||||
}
|
||||
|
||||
mFactories.Remove(aClass);
|
||||
entry.Remove();
|
||||
|
||||
// This might leave a stale contractid -> factory mapping in
|
||||
// place, so null out the factory entry (see
|
||||
|
||||
Reference in New Issue
Block a user