Bug 1480361 - Tweak handling of removed entries in HashTable::lookup(). r=luke
authorNicholas Nethercote <nnethercote@mozilla.com>
Fri, 03 Aug 2018 10:03:31 +1000
changeset 826229 d9baec9cf420acf68530b10bca19f67b72e3cb2b
parent 826228 d4ca2c8982afbcac4494d91b65cff5c64e59498a
child 826230 6c0410ddd1f6950a7398321c10b520ac1d378ed2
push id118275
push userbmo:dharvey@mozilla.com
push dateFri, 03 Aug 2018 11:44:33 +0000
reviewersluke
bugs1480361
milestone63.0a1
Bug 1480361 - Tweak handling of removed entries in HashTable::lookup(). r=luke There are two improvements here. - When we're just doing a lookup (i.e. aCollisionBit==0), we don't need to do any special handling of removed entries. (Inlining means that the removed entry code is entirely removed for lookups.) - When we're doing an insertion (i.e. aCollisionBit==sCollisionBit), we now stop adding collision markings once we find a removed entry, because they're unnecessary after that point. This change brings the code in alignment with PLDHashTable::SearchTable().
mfbt/HashTable.h
--- a/mfbt/HashTable.h
+++ b/mfbt/HashTable.h
@@ -1761,22 +1761,20 @@ private:
 
     // Collision: double hash.
     DoubleHash dh = hash2(aKeyHash);
 
     // Save the first removed entry pointer so we can recycle later.
     Entry* firstRemoved = nullptr;
 
     while (true) {
-      if (MOZ_UNLIKELY(entry->isRemoved())) {
-        if (!firstRemoved) {
+      if (aCollisionBit == sCollisionBit && !firstRemoved) {
+        if (MOZ_UNLIKELY(entry->isRemoved())) {
           firstRemoved = entry;
-        }
-      } else {
-        if (aCollisionBit == sCollisionBit) {
+        } else {
           entry->setCollision();
         }
       }
 
       METER(mStats.mSteps++);
       h1 = applyDoubleHash(h1, dh);
 
       entry = &mTable[h1];