Bug 1367209 part 4 - Use LookupForAdd to avoid an additional hashtable lookup when inserting a new entry. r=jfkthame
authorMats Palmgren <mats@mozilla.com>
Sun, 04 Jun 2017 16:45:15 +0200
changeset 410359 22108a33acd5ce6ecbf0ca5f696a01591c5c0ca1
parent 410358 1b9d1468f7b4c1eb9b40fb19137f252bb113aff4
child 410360 5e9c3d9dd68e04f11da55fb3a85b99cbebb44dc7
push id7391
push usermtabara@mozilla.com
push dateMon, 12 Jun 2017 13:08:53 +0000
treeherdermozilla-beta@2191d7f87e2e [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjfkthame
bugs1367209
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 1367209 part 4 - Use LookupForAdd to avoid an additional hashtable lookup when inserting a new entry. r=jfkthame MozReview-Commit-ID: u24jLUvoCJ
layout/base/nsCounterManager.cpp
--- a/layout/base/nsCounterManager.cpp
+++ b/layout/base/nsCounterManager.cpp
@@ -233,24 +233,19 @@ nsCounterManager::AddResetOrIncrement(ns
     node->Calc(counterList);
   }
   return false;
 }
 
 nsCounterList*
 nsCounterManager::CounterListFor(const nsSubstring& aCounterName)
 {
-  // XXX Why doesn't nsTHashtable provide an API that allows us to use
-  // get/put in one hashtable lookup?
-  nsCounterList* counterList;
-  if (!mNames.Get(aCounterName, &counterList)) {
-    counterList = new nsCounterList();
-    mNames.Put(aCounterName, counterList);
-  }
-  return counterList;
+  return mNames.LookupForAdd(aCounterName).OrInsert([]() {
+    return new nsCounterList();
+  });
 }
 
 void
 nsCounterManager::RecalcAll()
 {
   for (auto iter = mNames.Iter(); !iter.Done(); iter.Next()) {
     nsCounterList* list = iter.UserData();
     if (list->IsDirty()) {