gecko-dev/xpcom/ds
L. David Baron 443904b36a Bug 1352888 - Don't set the collision flag when adding to PLDHashTable if we've already found the entry we're going to add. r=njn
PLDHashTable's entry store has two types of unoccupied entries:  free
entries and removed entries.  The search of a chain of entries
(determined by the hash value) in the entry store to search for an entry
can stop at free entries, but it continues across removed entries,
because removed entries are entries that may have been skipped over when
we were adding the value we're searching for to the hash, but have since
been removed.  For live entries, we also maintain this distinction by
using one bit of storage for a collision flag, which notes that if the
hashtable entry is removed, its place in the entry store must become a
removed entry rather than a free entry.

When we add a new entry to the table, Add's semantics require that we
return an existing entry if there is one, and only create a new entry if
no existing entry exists.  (Bug 1352198 suggests the possibility of a
faster alternative Add API where the caller guarantees that the key is
not already in the hashtable.)  When we search for the existing entry,
we must thus continue the search across removed entries, even though we
record the first removed entry found to return if the search for an
existing entry fails.

The existing code adds the collision flag through the entire table
search during an Add.  This patch changes that behavior so that we only
add the collision flag prior to finding the first removed entry.  Adding
it after we find the first removed entry is unnecessary, since we are
not making that entry part of a path to a new entry.  If it is part of a
path to an existing entry, it will already have the collision flag set.

This patch effectively puts an if (!firstRemoved) around the else branch
of the if (MOZ_UNLIKELY(EntryIsRemoved(entry))), and then refactors that
condition outwards since it is now around the contents of both the if
and else branches.

MozReview-Commit-ID: CsXnMYttHVy

--HG--
extra : transplant_source : W4%B8%BA%D5p%102%1B%8D%83%23%E0s%B3%B0f%0D%05%AE
2017-04-04 20:59:21 -07:00
..
ArenaAllocator.h Bug 943156 - Add a templated ArenaAllocator. r=froydnj 2017-03-30 16:46:55 -07:00
ArenaAllocatorExtensions.h Bug 1351732 - Part 1: Add an ArenaAllocator strdup extension. r=froydnj 2017-03-30 16:46:56 -07:00
ArrayIterator.h Bug 1342303 part 1 - Make nsTArrayIterator an independent class. r=erahm 2017-02-24 16:14:06 +11:00
IncrementalTokenizer.cpp Bug 1322825 - Incremental tokenizer. r=froydnj 2017-02-06 10:49:00 -05:00
IncrementalTokenizer.h Bug 1322825 - Incremental tokenizer. r=froydnj 2017-02-06 10:49:00 -05:00
moz.build Bug 1351732 - Part 2: Replace use of PLArena with ArenaAllocator in xpcom. r=froydnj 2017-03-30 16:46:58 -07:00
nsArray.cpp Bug 1311191 - Part 1: Add nsISupportsArray-like iteration to nsArray. r=froydnj 2016-10-24 13:24:26 -07:00
nsArray.h Bug 1311191 - Part 1: Add nsISupportsArray-like iteration to nsArray. r=froydnj 2016-10-24 13:24:26 -07:00
nsArrayEnumerator.cpp Bug 1332631 part C - file moves from xpcom/glue to xpcom/ds, r=froydnj 2017-01-20 13:59:21 -05:00
nsArrayEnumerator.h Bug 1332631 part C - file moves from xpcom/glue to xpcom/ds, r=froydnj 2017-01-20 13:59:21 -05:00
nsArrayUtils.cpp Bug 1332631 part C - file moves from xpcom/glue to xpcom/ds, r=froydnj 2017-01-20 13:59:21 -05:00
nsArrayUtils.h Bug 1332631 part C - file moves from xpcom/glue to xpcom/ds, r=froydnj 2017-01-20 13:59:21 -05:00
nsAtomService.cpp
nsAtomService.h
nsAtomTable.cpp Bug 1351303, add main thread only cache for nsIAtoms to speed up atomization, r=froydnj 2017-04-03 23:13:18 +03:00
nsAtomTable.h Bug 1275755 - Use an explicit init routine for the atom table. r=froydnj 2016-05-28 17:08:05 +01:00
nsBaseHashtable.h Bug 1332631 part C - file moves from xpcom/glue to xpcom/ds, r=froydnj 2017-01-20 13:59:21 -05:00
nsCharSeparatedTokenizer.h
nsCheapSets.h Bug 1268772 (part 1) - Remove nsCheapSet::Put()'s return value. r=erahm. 2016-04-28 15:59:58 +10:00
nsClassHashtable.h Bug 1332631 part C - file moves from xpcom/glue to xpcom/ds, r=froydnj 2017-01-20 13:59:21 -05:00
nsCOMArray.cpp Bug 1332631 part C - file moves from xpcom/glue to xpcom/ds, r=froydnj 2017-01-20 13:59:21 -05:00
nsCOMArray.h Bug 1342303 part 6 - Remove nsCOMArray::Enumerate{Forwards,Backwards}. r=erahm 2017-02-24 21:37:07 +11:00
nsCRT.cpp
nsCRT.h Bug 1232696 - Remove NS_DECL_AND_IMPL_ZEROING_OPERATOR_NEW as it causes segfaulting for GCC 6 builds (5 of 5, fixes for docshell/). r=bzbarsky. 2017-01-24 17:12:10 +01:00
nsDataHashtable.h Bug 1332631 part C - file moves from xpcom/glue to xpcom/ds, r=froydnj 2017-01-20 13:59:21 -05:00
nsDeque.cpp Bug 1332631 part C - file moves from xpcom/glue to xpcom/ds, r=froydnj 2017-01-20 13:59:21 -05:00
nsDeque.h Bug 1336215 - Optimize iterator if nsDeque is const - r=froydnj 2017-02-03 13:08:10 +11:00
nsEnumeratorUtils.cpp Bug 1332631 part C - file moves from xpcom/glue to xpcom/ds, r=froydnj 2017-01-20 13:59:21 -05:00
nsEnumeratorUtils.h Bug 1332631 part C - file moves from xpcom/glue to xpcom/ds, r=froydnj 2017-01-20 13:59:21 -05:00
nsExpirationTracker.h Shutdown XPCOM-dependent resources in ImageBridgeChild at the appropriate time. (bug 1298938 part 3.1, r=mattwoodrow) 2016-09-13 16:30:57 -07:00
nsHashKeys.h Bug 1332631 part C - file moves from xpcom/glue to xpcom/ds, r=froydnj 2017-01-20 13:59:21 -05:00
nsHashPropertyBag.cpp
nsHashPropertyBag.h
nsIArray.idl
nsIArrayExtensions.idl Bug 1311191 - Part 1: Add nsISupportsArray-like iteration to nsArray. r=froydnj 2016-10-24 13:24:26 -07:00
nsIAtom.idl Bug 1351303, add main thread only cache for nsIAtoms to speed up atomization, r=froydnj 2017-04-03 23:13:18 +03:00
nsIAtomService.idl
nsIHashable.idl
nsIINIParser.idl
nsIMutableArray.idl Bug 1311191 - Part 1: Add nsISupportsArray-like iteration to nsArray. r=froydnj 2016-10-24 13:24:26 -07:00
nsINIParserImpl.cpp
nsINIParserImpl.h
nsINIProcessor.js Bug 1285063 - Part 1: Add a helper to XPCOMUtils to iterate over entries in a category. r=kmag 2016-07-11 17:33:06 -07:00
nsINIProcessor.manifest
nsInterfaceHashtable.h Bug 1332631 part C - file moves from xpcom/glue to xpcom/ds, r=froydnj 2017-01-20 13:59:21 -05:00
nsIObserver.idl
nsIObserverService.idl
nsIPersistentProperties2.idl
nsIPersistentProperties.h
nsIProperties.idl
nsIProperty.idl
nsIPropertyBag2.idl
nsIPropertyBag.idl
nsISerializable.idl
nsISimpleEnumerator.idl
nsIStringEnumerator.idl
nsISupportsIterators.idl
nsISupportsPrimitives.idl Bug 1329718 - remove nsISupportsVoid and associated machinery; r=erahm 2017-01-10 16:31:48 -05:00
nsIVariant.idl
nsIWindowsRegKey.idl
nsIWritablePropertyBag2.idl
nsIWritablePropertyBag.idl
nsJSThingHashtable.h Bug 1332631 part C - file moves from xpcom/glue to xpcom/ds, r=froydnj 2017-01-20 13:59:21 -05:00
nsMathUtils.h
nsObserverList.cpp Backed out changeset 491237dbcb5d (bug 1323207) 2016-12-16 20:06:43 +01:00
nsObserverList.h Bug 1268772 (part 5) - Use MOZ_MUST_USE in other parts of xpcom/ds/. r=erahm. 2016-04-28 17:11:17 +10:00
nsObserverService.cpp Bug 1297658 - Avoid unnecessary checking in memory reporters. r=erahm. 2016-08-24 15:23:45 +10:00
nsObserverService.h Bug 1268772 (part 5) - Use MOZ_MUST_USE in other parts of xpcom/ds/. r=erahm. 2016-04-28 17:11:17 +10:00
nsPersistentProperties.cpp Bug 1351732 - Part 2: Replace use of PLArena with ArenaAllocator in xpcom. r=froydnj 2017-03-30 16:46:58 -07:00
nsPersistentProperties.h Bug 1351732 - Part 2: Replace use of PLArena with ArenaAllocator in xpcom. r=froydnj 2017-03-30 16:46:58 -07:00
nsPointerHashKeys.h Bug 1332631 part C - file moves from xpcom/glue to xpcom/ds, r=froydnj 2017-01-20 13:59:21 -05:00
nsProperties.cpp
nsProperties.h
nsQuickSort.cpp Bug 1332631 part C - file moves from xpcom/glue to xpcom/ds, r=froydnj 2017-01-20 13:59:21 -05:00
nsQuickSort.h Bug 1332631 part C - file moves from xpcom/glue to xpcom/ds, r=froydnj 2017-01-20 13:59:21 -05:00
nsRefPtrHashtable.h Bug 1332631 part C - file moves from xpcom/glue to xpcom/ds, r=froydnj 2017-01-20 13:59:21 -05:00
nsStaticAtom.h Bug 1277106 - Part 4: Remove MOZ_UTF16() macro. r=Waldo 2016-07-19 21:07:53 -07:00
nsStaticNameTable.cpp Bug 1350423 - Remove unused PL_ARENA macro in nsStaticNameTable. r=froydnj 2017-03-27 09:15:38 -07:00
nsStaticNameTable.h
nsStringEnumerator.cpp Bug 1262399 - remove Impl suffixes from nsSupports* implementations; r=mccr8 2016-05-03 15:25:41 -05:00
nsStringEnumerator.h Bug 1268772 (part 5) - Use MOZ_MUST_USE in other parts of xpcom/ds/. r=erahm. 2016-04-28 17:11:17 +10:00
nsSupportsPrimitives.cpp Bug 1329718 - remove nsISupportsVoid and associated machinery; r=erahm 2017-01-10 16:31:48 -05:00
nsSupportsPrimitives.h Bug 1329718 - remove nsISupportsVoid and associated machinery; r=erahm 2017-01-10 16:31:48 -05:00
nsTArray-inl.h Bug 1348123 - Add release bounds checking when inserting and replacing. r=froydnj 2017-03-17 16:40:53 -07:00
nsTArray.cpp Bug 1338574 - Part 7: Use MOZ_CRASH_UNSAFE_PRINTF in XPCOM. r=froydnj 2017-02-21 18:02:03 +01:00
nsTArray.h Bug 1295611 - Add mozilla::Span. r=froydnj,gerv. 2017-03-31 13:32:18 +03:00
nsTArrayForwardDeclare.h Bug 1332631 part C - file moves from xpcom/glue to xpcom/ds, r=froydnj 2017-01-20 13:59:21 -05:00
nsTHashtable.h Bug 1332631 part C - file moves from xpcom/glue to xpcom/ds, r=froydnj 2017-01-20 13:59:21 -05:00
nsTObserverArray.cpp Bug 1332631 part C - file moves from xpcom/glue to xpcom/ds, r=froydnj 2017-01-20 13:59:21 -05:00
nsTObserverArray.h Bug 1332631 part C - file moves from xpcom/glue to xpcom/ds, r=froydnj 2017-01-20 13:59:21 -05:00
nsTPriorityQueue.h Bug 1332631 part C - file moves from xpcom/glue to xpcom/ds, r=froydnj 2017-01-20 13:59:21 -05:00
nsVariant.cpp Bug 1305202 - Use NullString() more and remove superfluous Truncates(). r=smaug 2016-09-23 21:10:01 -04:00
nsVariant.h Bug 1268772 (part 2) - Make infallible nsVariant methods return |void| instead of |nsresult|. r=erahm. 2016-04-29 13:47:44 +10:00
nsWhitespaceTokenizer.h
nsWindowsRegKey.cpp Bug 1305422 - followup - use correct check for memory allocation failure in nsWindowsRegKey.cpp; r=bustage 2016-09-30 01:56:28 -04:00
nsWindowsRegKey.h Bug 1268772 (part 3) - Remove NS_NewWindowsRegKey()'s return value. r=erahm. 2016-05-02 09:06:45 +10:00
Observer.h Bug 1332631 part C - file moves from xpcom/glue to xpcom/ds, r=froydnj 2017-01-20 13:59:21 -05:00
PLDHashTable.cpp Bug 1352888 - Don't set the collision flag when adding to PLDHashTable if we've already found the entry we're going to add. r=njn 2017-04-04 20:59:21 -07:00
PLDHashTable.h Bug 1332631 part C - file moves from xpcom/glue to xpcom/ds, r=froydnj 2017-01-20 13:59:21 -05:00
StickyTimeDuration.h
Tokenizer.cpp Bug 1340581 - Add some release-grade assertions to mozilla::Tokenizer to catch string overflows. r=froydnj 2017-02-22 06:53:00 -05:00
Tokenizer.h Bug 1322825 - Incremental tokenizer. r=froydnj 2017-02-06 10:49:00 -05:00