From d12003b7e5edd2005321d82d9471330b0cc01d1c Mon Sep 17 00:00:00 2001 From: Nicholas Nethercote Date: Tue, 14 Aug 2018 11:19:39 +1000 Subject: [PATCH] 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`. --HG-- extra : rebase_source : 56e9edd012f4a400ac366895d05ea93fb09ec6b3 --- mfbt/HashTable.h | 25 +++++++++++++------------ 1 file changed, 13 insertions(+), 12 deletions(-) diff --git a/mfbt/HashTable.h b/mfbt/HashTable.h index 140b5c922cb8..be33839e0a9a 100644 --- a/mfbt/HashTable.h +++ b/mfbt/HashTable.h @@ -1444,7 +1444,7 @@ public: { if (mRekeyed) { mTable.mGen++; - mTable.checkOverRemoved(); + mTable.rehashIfOverRemoved(); } if (mRemoved) { @@ -1870,7 +1870,7 @@ private: 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 @@ -1879,23 +1879,24 @@ private: 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(); } } @@ -1917,7 +1918,7 @@ private: #endif } - void checkUnderloaded() + void shrinkIfUnderloaded() { if (underloaded()) { (void)changeTableSize(capacity() / 2, DontReportFailure); @@ -2008,7 +2009,7 @@ public: } // 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() { @@ -2169,7 +2170,7 @@ public: aPtr.mKeyHash |= sCollisionBit; } else { // Preserve the validity of |aPtr.mEntry|. - RebuildStatus status = checkOverloaded(); + RebuildStatus status = rehashIfOverloaded(); if (status == RehashFailed) { return false; } @@ -2212,7 +2213,7 @@ public: if (!EnsureHash(aLookup)) { return false; } - if (checkOverloaded() == RehashFailed) { + if (rehashIfOverloaded() == RehashFailed) { return false; } putNewInfallible(aLookup, std::forward(aArgs)...); @@ -2250,7 +2251,7 @@ public: MOZ_ASSERT(aPtr.found()); MOZ_ASSERT(aPtr.mGeneration == generation()); remove(*aPtr.mEntry); - checkUnderloaded(); + shrinkIfUnderloaded(); } void rekeyWithoutRehash(Ptr aPtr, const Lookup& aLookup, const Key& aKey) @@ -2268,7 +2269,7 @@ public: void rekeyAndMaybeRehash(Ptr aPtr, const Lookup& aLookup, const Key& aKey) { rekeyWithoutRehash(aPtr, aLookup, aKey); - checkOverRemoved(); + rehashIfOverRemoved(); } };