From de8fceb34dae6f99fe06c0be0b0c9fe9dfa12272 Mon Sep 17 00:00:00 2001 From: Nicholas Nethercote Date: Mon, 7 Sep 2015 19:20:12 -0700 Subject: [PATCH] Bug 1202526 (part 1) - Add PLDHashTable::RemoveEntry(). r=froydnj. This patch also consolidates the shrink handling so it's now entirely within ShrinkIfAppropriate(). --- xpcom/glue/pldhash.cpp | 22 +++++++++++++--------- xpcom/glue/pldhash.h | 13 ++++++++++++- 2 files changed, 25 insertions(+), 10 deletions(-) diff --git a/xpcom/glue/pldhash.cpp b/xpcom/glue/pldhash.cpp index 8f0333ced47d..22781ce9c942 100644 --- a/xpcom/glue/pldhash.cpp +++ b/xpcom/glue/pldhash.cpp @@ -662,18 +662,22 @@ PLDHashTable::Remove(const void* aKey) ComputeKeyHash(aKey)) : nullptr; if (entry) { - // Clear this entry and mark it as "removed". RawRemove(entry); - - // Shrink if alpha is <= .25 and the table isn't too small already. - uint32_t capacity = Capacity(); - if (capacity > kMinCapacity && - mEntryCount <= MinLoad(capacity)) { - (void) ChangeTable(-1); - } + ShrinkIfAppropriate(); } } +void +PLDHashTable::RemoveEntry(PLDHashEntryHdr* aEntry) +{ +#ifdef DEBUG + AutoWriteOp op(mChecker); +#endif + + RawRemove(aEntry); + ShrinkIfAppropriate(); +} + PLDHashEntryHdr* PL_DHASH_FASTCALL PL_DHashTableSearch(PLDHashTable* aTable, const void* aKey) { @@ -709,7 +713,7 @@ PLDHashTable::RawRemove(PLDHashEntryHdr* aEntry) MOZ_ASSERT(mEntryStore.Get()); - NS_ASSERTION(EntryIsLive(aEntry), "EntryIsLive(aEntry)"); + MOZ_ASSERT(EntryIsLive(aEntry), "EntryIsLive(aEntry)"); // Load keyHash first in case clearEntry() goofs it. PLDHashNumber keyHash = aEntry->mKeyHash; diff --git a/xpcom/glue/pldhash.h b/xpcom/glue/pldhash.h index e77e623d1bf1..4d330baec227 100644 --- a/xpcom/glue/pldhash.h +++ b/xpcom/glue/pldhash.h @@ -350,12 +350,23 @@ public: // table.Remove(key); // // If |key|'s entry is found, it is cleared (via table->mOps->clearEntry). + // The table's capacity may be reduced afterwards. void Remove(const void* aKey); + // To remove an entry found by a prior search, call: + // + // table.RemoveEntry(entry); + // + // The entry, which must be present and in use, is cleared (via + // table->mOps->clearEntry). The table's capacity may be reduced afterwards. + void RemoveEntry(PLDHashEntryHdr* aEntry); + // Remove an entry already accessed via Search() or Add(). // // NB: this is a "raw" or low-level method. It does not shrink the table if - // it is underloaded. Don't use it unless you know what you are doing. + // it is underloaded. Don't use it unless necessary and you know what you are + // doing, and if so, please explain in a comment why it is necessary instead + // of RemoveEntry(). void RawRemove(PLDHashEntryHdr* aEntry); // This function is equivalent to