Bug 1376127 - Use LookupForAdd instead of Get+Put in CycleCollectedJSRuntime::DeferredFinalize to avoid unnecessary hashtable lookups. r=froydnj
authorMats Palmgren <mats@mozilla.com>
Wed, 28 Jun 2017 01:03:18 +0200
changeset 402136 eec670cff2ce14492b462047e7f0082634189183
parent 402135 4692d0721273365c45dec0c662d6149fd9f01993
child 402137 d362c2910b39c4d4468eb77e3b595270980edb78
push idunknown
push userunknown
push dateunknown
reviewersfroydnj
bugs1376127
milestone56.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1376127 - Use LookupForAdd instead of Get+Put in CycleCollectedJSRuntime::DeferredFinalize to avoid unnecessary hashtable lookups. r=froydnj MozReview-Commit-ID: 1lEnh9yTQUH
xpcom/base/CycleCollectedJSRuntime.cpp
--- a/xpcom/base/CycleCollectedJSRuntime.cpp
+++ b/xpcom/base/CycleCollectedJSRuntime.cpp
@@ -1241,22 +1241,21 @@ CycleCollectedJSRuntime::NurseryWrapperP
     JS::PersistentRooted<JSObject*>(mJSRuntime, aWrapper));
 }
 
 void
 CycleCollectedJSRuntime::DeferredFinalize(DeferredFinalizeAppendFunction aAppendFunc,
                                           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); });
   }
 }
 
 void
 CycleCollectedJSRuntime::DeferredFinalize(nsISupports* aSupports)
 {
   typedef DeferredFinalizerImpl<nsISupports> Impl;
   DeferredFinalize(Impl::AppendDeferredFinalizePointer, Impl::DeferredFinalize,