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
This commit is contained in:
Nicholas Nethercote 2018-08-14 11:19:39 +10:00
Родитель d378adb5b7
Коммит d12003b7e5
1 изменённых файлов: 13 добавлений и 12 удалений

Просмотреть файл

@ -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<HashPolicy>(aLookup)) {
return false;
}
if (checkOverloaded() == RehashFailed) {
if (rehashIfOverloaded() == RehashFailed) {
return false;
}
putNewInfallible(aLookup, std::forward<Args>(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();
}
};