Bug 1173600 (part 2) - Move post-enumeration shrinking code into its own function. r=froydnj.
authorNicholas Nethercote <nnethercote@mozilla.com>
Wed, 10 Jun 2015 16:36:02 -0700
changeset 280259 3df0d30e2211e86ce82bdbcd30ae6e059e24249d
parent 280258 264d64780bb2bbb90732d029db76ce23fe0cb734
child 280260 12f57a3af088cd45a4feccb017bedd90016e0f6b
push id4932
push userjlund@mozilla.com
push dateMon, 10 Aug 2015 18:23:06 +0000
treeherdermozilla-beta@6dd5a4f5f745 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersfroydnj
bugs1173600
milestone41.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 1173600 (part 2) - Move post-enumeration shrinking code into its own function. r=froydnj. This will allow it to be re-used by the removing iterator class.
xpcom/glue/pldhash.cpp
xpcom/glue/pldhash.h
--- a/xpcom/glue/pldhash.cpp
+++ b/xpcom/glue/pldhash.cpp
@@ -756,16 +756,37 @@ PLDHashTable::RawRemove(PLDHashEntryHdr*
 }
 
 void
 PL_DHashTableRawRemove(PLDHashTable* aTable, PLDHashEntryHdr* aEntry)
 {
   aTable->RawRemove(aEntry);
 }
 
+// Shrink or compress if a quarter or more of all entries are removed, or if the
+// table is underloaded according to the minimum alpha, and is not minimal-size
+// already.
+void
+PLDHashTable::ShrinkIfAppropriate()
+{
+  uint32_t capacity = Capacity();
+  if (mRemovedCount >= capacity >> 2 ||
+      (capacity > PL_DHASH_MIN_CAPACITY && mEntryCount <= MinLoad(capacity))) {
+    METER(mStats.mEnumShrinks++);
+
+    uint32_t log2;
+    BestCapacity(mEntryCount, &capacity, &log2);
+
+    int32_t deltaLog2 = log2 - (PL_DHASH_BITS - mHashShift);
+    MOZ_ASSERT(deltaLog2 <= 0);
+
+    (void) ChangeTable(deltaLog2);
+  }
+}
+
 MOZ_ALWAYS_INLINE uint32_t
 PLDHashTable::Enumerate(PLDHashEnumerator aEtor, void* aArg)
 {
   if (!mEntryStore) {
     return 0;
   }
 
   INCREMENT_RECURSION_LEVEL(this);
@@ -800,36 +821,21 @@ PLDHashTable::Enumerate(PLDHashEnumerato
     entryAddr += mEntrySize;
     if (entryAddr >= entryLimit) {
       entryAddr -= tableSize;
     }
   }
 
   MOZ_ASSERT(!didRemove || mRecursionLevel == 1);
 
-  /*
-   * Shrink or compress if a quarter or more of all entries are removed, or
-   * if the table is underloaded according to the minimum alpha, and is not
-   * minimal-size already.  Do this only if we removed above, so non-removing
-   * enumerations can count on stable |mEntryStore| until the next
-   * Add, Remove, or removing-Enumerate.
-   */
-  if (didRemove &&
-      (mRemovedCount >= capacity >> 2 ||
-       (capacity > PL_DHASH_MIN_CAPACITY &&
-        mEntryCount <= MinLoad(capacity)))) {
-    METER(mStats.mEnumShrinks++);
-
-    uint32_t log2;
-    BestCapacity(mEntryCount, &capacity, &log2);
-
-    int32_t deltaLog2 = log2 - (PL_DHASH_BITS - mHashShift);
-    MOZ_ASSERT(deltaLog2 <= 0);
-
-    (void) ChangeTable(deltaLog2);
+  // Shrink the table if appropriate. Do this only if we removed above, so
+  // non-removing enumerations can count on stable |mEntryStore| until the next
+  // Add, Remove, or removing-Enumerate.
+  if (didRemove) {
+    ShrinkIfAppropriate();
   }
 
   DECREMENT_RECURSION_LEVEL(this);
 
   return i;
 }
 
 uint32_t
--- a/xpcom/glue/pldhash.h
+++ b/xpcom/glue/pldhash.h
@@ -355,16 +355,18 @@ private:
   template <SearchReason Reason>
   PLDHashEntryHdr* PL_DHASH_FASTCALL
     SearchTable(const void* aKey, PLDHashNumber aKeyHash);
 
   PLDHashEntryHdr* PL_DHASH_FASTCALL FindFreeEntry(PLDHashNumber aKeyHash);
 
   bool ChangeTable(int aDeltaLog2);
 
+  void ShrinkIfAppropriate();
+
   PLDHashTable(const PLDHashTable& aOther) = delete;
   PLDHashTable& operator=(const PLDHashTable& aOther) = delete;
 };
 
 /*
  * Compute the hash code for a given key to be looked up, added, or removed
  * from aTable.  A hash code may have any PLDHashNumber value.
  */