Bug 1376127 - Use LookupForAdd instead of Get+Put in CycleCollectedJSRuntime::DeferredFinalize to avoid unnecessary hashtable lookups. r=froydnj

MozReview-Commit-ID: 1lEnh9yTQUH
This commit is contained in:
Mats Palmgren
2017-06-28 01:03:18 +02:00
parent 05d086cda1
commit ea70125498

View File

@@ -1246,12 +1246,11 @@ CycleCollectedJSRuntime::DeferredFinalize(DeferredFinalizeAppendFunction aAppend
DeferredFinalizeFunction aFunc,
void* aThing)
{
void* thingArray = nullptr;
bool hadThingArray = mDeferredFinalizerTable.Get(aFunc, &thingArray);
thingArray = aAppendFunc(thingArray, aThing);
if (!hadThingArray) {
mDeferredFinalizerTable.Put(aFunc, thingArray);
if (auto entry = mDeferredFinalizerTable.LookupForAdd(aFunc)) {
aAppendFunc(entry.Data(), aThing);
} else {
entry.OrInsert(
[aAppendFunc, aThing] () { return aAppendFunc(nullptr, aThing); });
}
}