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.
This commit is contained in:
Nicholas Nethercote 2015-06-10 16:36:02 -07:00
parent c412098e05
commit b0a39a3a7c
2 changed files with 28 additions and 20 deletions

View File

@ -761,6 +761,27 @@ 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)
{
@ -805,26 +826,11 @@ PLDHashTable::Enumerate(PLDHashEnumerator aEtor, void* aArg)
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);

View File

@ -360,6 +360,8 @@ private:
bool ChangeTable(int aDeltaLog2);
void ShrinkIfAppropriate();
PLDHashTable(const PLDHashTable& aOther) = delete;
PLDHashTable& operator=(const PLDHashTable& aOther) = delete;
};