Bug 1371952 - Use LookupForAdd/LookupRemoveIf to avoid unnecessary hashtable lookups. r=froydnj

MozReview-Commit-ID: 5hprMT4Gc42
This commit is contained in:
Mats Palmgren 2017-06-14 01:54:26 +02:00
Родитель 68da6780f3
Коммит 2ee1457c5b
1 изменённых файлов: 14 добавлений и 15 удалений

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

@ -453,14 +453,16 @@ already_AddRefed<ParticularProcessPriorityManager>
ProcessPriorityManagerImpl::GetParticularProcessPriorityManager(
ContentParent* aContentParent)
{
RefPtr<ParticularProcessPriorityManager> pppm;
uint64_t cpId = aContentParent->ChildID();
mParticularManagers.Get(cpId, &pppm);
if (!pppm) {
pppm = new ParticularProcessPriorityManager(aContentParent);
pppm->Init();
mParticularManagers.Put(cpId, pppm);
auto entry = mParticularManagers.LookupForAdd(cpId);
RefPtr<ParticularProcessPriorityManager> pppm = entry.OrInsert(
[aContentParent]() {
return new ParticularProcessPriorityManager(aContentParent);
});
if (!entry) {
// We created a new entry.
pppm->Init();
FireTestOnlyObserverNotification("process-created",
nsPrintfCString("%" PRIu64, cpId));
}
@ -501,15 +503,12 @@ ProcessPriorityManagerImpl::ObserveContentParentDestroyed(nsISupports* aSubject)
props->GetPropertyAsUint64(NS_LITERAL_STRING("childID"), &childID);
NS_ENSURE_TRUE_VOID(childID != CONTENT_PROCESS_ID_UNKNOWN);
RefPtr<ParticularProcessPriorityManager> pppm;
mParticularManagers.Get(childID, &pppm);
if (pppm) {
pppm->ShutDown();
mParticularManagers.Remove(childID);
mHighPriorityChildIDs.RemoveEntry(childID);
}
mParticularManagers.LookupRemoveIf(childID,
[this, childID] (RefPtr<ParticularProcessPriorityManager>& aValue) {
aValue->ShutDown();
mHighPriorityChildIDs.RemoveEntry(childID);
return true; // remove it
});
}
void