Bug 1483062 - Rename some HashTable methods. r=luke
authorNicholas Nethercote <nnethercote@mozilla.com>
Tue, 14 Aug 2018 11:19:39 +1000
changeset 431942 43e351bda401e80292efbde947e56d1893b95903
parent 431941 f1e1cf1d42ec20c547a46cee30163a0b41fa36f4
child 431943 2d9e3360e858f6c502ae9728280efb0f12daa7e4
push id34456
push usertoros@mozilla.com
push dateThu, 16 Aug 2018 21:33:21 +0000
treeherdermozilla-central@72442cf86f54 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersluke
bugs1483062
milestone63.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 1483062 - Rename some HashTable methods. r=luke Specifically: - checkOverloaded -> rehashIfOverloaded - checkUnderloaded -> shrinkIfUnderloaded - checkOverRemoved -> rehashIfOverRemoved Because I've always found that the `check` prefix doesn't clearly explain that the table might be changed, And: - shouldCompressTable -> overRemoved Because that matches `overloaded` and `underloaded`.
mfbt/HashTable.h
--- a/mfbt/HashTable.h
+++ b/mfbt/HashTable.h
@@ -1439,17 +1439,17 @@ public:
 
     void rekey(const Key& k) { rekey(k, k); }
 
     // Potentially rehashes the table.
     ~ModIterator()
     {
       if (mRekeyed) {
         mTable.mGen++;
-        mTable.checkOverRemoved();
+        mTable.rehashIfOverRemoved();
       }
 
       if (mRemoved) {
         mTable.compact();
       }
     }
   };
 
@@ -1865,42 +1865,43 @@ private:
       src->~Entry();
     }
 
     // All entries have been destroyed, no need to destroyTable.
     this->free_(oldTable, oldCapacity);
     return Rehashed;
   }
 
-  bool shouldCompressTable()
+  bool overRemoved()
   {
     // Succeed if a quarter or more of all entries are removed. Note that this
     // always succeeds if capacity() == 0 (i.e. entry storage has not been
     // allocated), which is what we want, because it means changeTableSize()
     // will allocate the requested capacity rather than doubling it.
     return mRemovedCount >= (capacity() >> 2);
   }
 
-  RebuildStatus checkOverloaded(FailureBehavior aReportFailure = ReportFailure)
+  RebuildStatus rehashIfOverloaded(
+    FailureBehavior aReportFailure = ReportFailure)
   {
     if (!overloaded()) {
       return NotOverloaded;
     }
 
-    uint32_t newCapacity = shouldCompressTable()
+    uint32_t newCapacity = overRemoved()
                          ? rawCapacity()
                          : rawCapacity() * 2;
     return changeTableSize(newCapacity, aReportFailure);
   }
 
   // Infallibly rehash the table if we are overloaded with removals.
-  void checkOverRemoved()
+  void rehashIfOverRemoved()
   {
     if (overloaded()) {
-      if (checkOverloaded(DontReportFailure) == RehashFailed) {
+      if (rehashIfOverloaded(DontReportFailure) == RehashFailed) {
         rehashTableInPlace();
       }
     }
   }
 
   void remove(Entry& aEntry)
   {
     MOZ_ASSERT(mTable);
@@ -1912,17 +1913,17 @@ private:
       aEntry.clearLive();
     }
     mEntryCount--;
 #ifdef DEBUG
     mMutationCount++;
 #endif
   }
 
-  void checkUnderloaded()
+  void shrinkIfUnderloaded()
   {
     if (underloaded()) {
       (void)changeTableSize(capacity() / 2, DontReportFailure);
     }
   }
 
   // This is identical to changeTableSize(currentSize), but without requiring
   // a second table.  We do this by recycling the collision bits to tell us if
@@ -2003,17 +2004,17 @@ public:
     mRemovedCount = 0;
     mEntryCount = 0;
 #ifdef DEBUG
     mMutationCount++;
 #endif
   }
 
   // Resize the table down to the smallest capacity that doesn't overload the
-  // table. Since we call checkUnderloaded() on every remove, you only need
+  // table. Since we call shrinkIfUnderloaded() on every remove, you only need
   // to call this after a bulk removal of items done without calling remove().
   void compact()
   {
     if (empty()) {
       // Free the entry storage.
       this->free_(mTable, capacity());
       mGen++;
       mHashShift = hashShift(0);  // gives minimum capacity on regrowth
@@ -2164,17 +2165,17 @@ public:
     if (aPtr.mEntry->isRemoved()) {
       if (!this->checkSimulatedOOM()) {
         return false;
       }
       mRemovedCount--;
       aPtr.mKeyHash |= sCollisionBit;
     } else {
       // Preserve the validity of |aPtr.mEntry|.
-      RebuildStatus status = checkOverloaded();
+      RebuildStatus status = rehashIfOverloaded();
       if (status == RehashFailed) {
         return false;
       }
       if (status == NotOverloaded && !this->checkSimulatedOOM()) {
         return false;
       }
       if (status == Rehashed) {
         aPtr.mEntry = &findNonLiveEntry(aPtr.mKeyHash);
@@ -2207,17 +2208,17 @@ public:
   MOZ_MUST_USE bool putNew(const Lookup& aLookup, Args&&... aArgs)
   {
     if (!this->checkSimulatedOOM()) {
       return false;
     }
     if (!EnsureHash<HashPolicy>(aLookup)) {
       return false;
     }
-    if (checkOverloaded() == RehashFailed) {
+    if (rehashIfOverloaded() == RehashFailed) {
       return false;
     }
     putNewInfallible(aLookup, std::forward<Args>(aArgs)...);
     return true;
   }
 
   // Note: |aLookup| may be a reference to a piece of |u|, so this function
   // must take care not to use |aLookup| after moving |u|.
@@ -2245,17 +2246,17 @@ public:
 
   void remove(Ptr aPtr)
   {
     MOZ_ASSERT(mTable);
     ReentrancyGuard g(*this);
     MOZ_ASSERT(aPtr.found());
     MOZ_ASSERT(aPtr.mGeneration == generation());
     remove(*aPtr.mEntry);
-    checkUnderloaded();
+    shrinkIfUnderloaded();
   }
 
   void rekeyWithoutRehash(Ptr aPtr, const Lookup& aLookup, const Key& aKey)
   {
     MOZ_ASSERT(mTable);
     ReentrancyGuard g(*this);
     MOZ_ASSERT(aPtr.found());
     MOZ_ASSERT(aPtr.mGeneration == generation());
@@ -2263,16 +2264,16 @@ public:
     HashPolicy::setKey(t, const_cast<Key&>(aKey));
     remove(*aPtr.mEntry);
     putNewInfallibleInternal(aLookup, std::move(t));
   }
 
   void rekeyAndMaybeRehash(Ptr aPtr, const Lookup& aLookup, const Key& aKey)
   {
     rekeyWithoutRehash(aPtr, aLookup, aKey);
-    checkOverRemoved();
+    rehashIfOverRemoved();
   }
 };
 
 } // namespace detail
 } // namespace mozilla
 
 #endif /* mozilla_HashTable_h */