Bug 1361745 - Part 2: Avoid a double hashtable lookup for insertions in nsControllerCommandGroup::AddCommandToGroup; r=mystor
authorEhsan Akhgari <ehsan.akhgari@gmail.com>
Wed, 03 May 2017 11:25:37 -0400
changeset 357101 00b0dbfee0d6ce3f0533e238d4dc4f9920cf8540
parent 357100 d93f890967c0573ebe56a8dd56947f6d183739f5
child 357102 5fa6bc617e2f81c82fa58e0e64f6b2352a9adc0d
push id31782
push userkwierso@gmail.com
push dateMon, 08 May 2017 23:07:35 +0000
treeherdermozilla-central@b21b974d60d3 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmystor
bugs1361745
milestone55.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 1361745 - Part 2: Avoid a double hashtable lookup for insertions in nsControllerCommandGroup::AddCommandToGroup; r=mystor
dom/commandhandler/nsCommandGroup.cpp
--- a/dom/commandhandler/nsCommandGroup.cpp
+++ b/dom/commandhandler/nsCommandGroup.cpp
@@ -206,22 +206,19 @@ nsControllerCommandGroup::ClearGroupsHas
   mGroupsHash.Clear();
 }
 
 NS_IMETHODIMP
 nsControllerCommandGroup::AddCommandToGroup(const char* aCommand,
                                             const char* aGroup)
 {
   nsDependentCString groupKey(aGroup);
-  nsTArray<nsCString>* commandList = mGroupsHash.Get(groupKey);
-  if (!commandList) {
-    // make this list
-    commandList = new AutoTArray<nsCString, 8>;
-    mGroupsHash.Put(groupKey, commandList);
-  }
+  auto commandList = mGroupsHash.LookupForAdd(groupKey).OrInsert([]() {
+      return new AutoTArray<nsCString, 8>();
+    });
 
 #ifdef DEBUG
   nsCString* appended =
 #endif
   commandList->AppendElement(aCommand);
   NS_ASSERTION(appended, "Append failed");
 
   return NS_OK;