Skip to content

Commit 9e76c04

Browse files
committed
Bug 1695275 - Simplify hashtable clearing when there is no Clear operation. r=xpcom-reviewers,nika
Differential Revision: https://phabricator.services.mozilla.com/D106644
1 parent 3b548be commit 9e76c04

File tree

2 files changed

+13
-9
lines changed

2 files changed

+13
-9
lines changed

xpcom/ds/PLDHashTable.cpp

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -286,12 +286,14 @@ PLDHashTable::~PLDHashTable() {
286286
return;
287287
}
288288

289-
// Clear any remaining live entries.
290-
mEntryStore.ForEachSlot(Capacity(), mEntrySize, [&](const Slot& aSlot) {
291-
if (aSlot.IsLive()) {
292-
mOps->clearEntry(this, aSlot.ToEntry());
293-
}
294-
});
289+
// Clear any remaining live entries (if not trivially destructible).
290+
if (mOps->clearEntry) {
291+
mEntryStore.ForEachSlot(Capacity(), mEntrySize, [&](const Slot& aSlot) {
292+
if (aSlot.IsLive()) {
293+
mOps->clearEntry(this, aSlot.ToEntry());
294+
}
295+
});
296+
}
295297

296298
// Entry storage is freed last, by ~EntryStore().
297299
}
@@ -566,9 +568,11 @@ void PLDHashTable::RawRemove(Slot& aSlot) {
566568
MOZ_ASSERT(aSlot.IsLive());
567569

568570
// Load keyHash first in case clearEntry() goofs it.
569-
PLDHashEntryHdr* entry = aSlot.ToEntry();
570571
PLDHashNumber keyHash = aSlot.KeyHash();
571-
mOps->clearEntry(this, entry);
572+
if (mOps->clearEntry) {
573+
PLDHashEntryHdr* entry = aSlot.ToEntry();
574+
mOps->clearEntry(this, entry);
575+
}
572576
if (keyHash & kCollisionFlag) {
573577
aSlot.MarkRemoved();
574578
mRemovedCount++;

xpcom/ds/PLDHashTable.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -778,9 +778,9 @@ struct PLDHashTableOps {
778778
PLDHashHashKey hashKey;
779779
PLDHashMatchEntry matchEntry;
780780
PLDHashMoveEntry moveEntry;
781-
PLDHashClearEntry clearEntry;
782781

783782
// Optional hooks start here. If null, these are not called.
783+
PLDHashClearEntry clearEntry;
784784
PLDHashInitEntry initEntry;
785785
};
786786

0 commit comments

Comments
 (0)