gecko-dev/xpcom/ds
Gerald Squelart bad49db9b0 Bug 1479996 - Combine nsTArray::IndexOf and element access into lambda-friendly functions - r=froydnj
In many places, nsTArray::IndexOf is followed by accessing that element
(hopefully with `Elements() + index`, which skips unnecessary bounds checks.)
But this pattern introduces operations that could be avoided:
- IndexOf converts the address of the found element into an index,
- The caller must test for a special `NoIndex` value,
- On success, accesses convert that index back into the original address.

This patch introduces new 'ApplyIf...' functions that combine all these
operations in a more efficient ensemble: If the sought element is found, it is
passed by reference to a given callable object (usually a lambda); if not
found, another callable is invoked.
Depending on what they need, the first callable may take one of these parameter
lists: (), (size_t), (maybe-const elem_type&), (size_t, maybe-const elem_type&).
On top of removing the pointer->index->pointer operations in most cases,
invoking callables directly from ApplyIf is safer, as the array is guaranteed to
be untouched at this time.
Also, being templates taking function objects, in most cases the compiler should
be able to inline and optimize the search and its callables' code.

This patch gives example uses in nsTArray::Contains, and in
FrameProperties::GetInternal, SetInternal.
And FrameProperties::Has now calls Contains, which is more efficient because
the former code would compute an index (or NoIndex), and then convert that index
to a bool; whereas the new code directly produces a bool from within the search
algorithm.

Differential Revision: https://phabricator.services.mozilla.com/D2758

--HG--
extra : moz-landing-system : lando
2018-08-28 22:04:09 +00:00
..
tools Bug 1474739 - Part 3: Linting fixes on a CLOSED TREE, a=bustage 2018-08-01 18:23:21 -04:00
ArenaAllocator.h Bug 1406727 - Improve diagnostics in BuildDisplayList. r=froydnj 2018-02-06 12:21:31 +13:00
ArenaAllocatorExtensions.h Bug 1412416 - Part 2: Simplify ArenaStrdup for xpcom strings. r=froydnj 2017-10-27 13:26:47 -07:00
ArrayIterator.h
Atom.py Bug 1483121 - Generate static atom hash in StaticAtoms.py. r=njn,emilio 2018-08-15 15:52:42 +10:00
AtomArray.h Bug 1407843 part 1 - Introduce a global-level AtomArray type alias. r=froydnj 2017-10-13 11:59:23 +11:00
Dafsa.cpp Bug 1380154 - Part 1: Add the Chromium DAFSA generator. r=njn 2017-07-17 16:09:42 -07:00
Dafsa.h Bug 1380154 - Part 2: Generate a DAFSA and use it for eTLDs. r=jduell 2017-07-17 16:10:18 -07:00
HTMLAtoms.py Bug 1482782 - Part 1: Generate nsGkAtomList.h from a Python file. r=njn,hsivonen 2018-08-15 15:46:00 +10:00
IncrementalTokenizer.cpp Bug 1465585: Switch from mozilla::Move to std::move. r=froydnj 2018-06-01 10:45:27 +02:00
IncrementalTokenizer.h Bug 1463786 - Make mozilla::Tokenizer work also with char16_t, r=froydnj 2018-05-31 03:40:00 +03:00
Observer.h Bug 1469914 - Prevent the HAL from registering duplicate observers; r=froydnj 2018-06-22 00:35:08 +02:00
PLDHashTable.cpp Bug 1477626 - Move ScrambleHashCode() from js/src/Utility.h to mfbt/HashFunctions.h. r=Waldo 2018-07-26 18:52:47 +10:00
PLDHashTable.h Bug 1477626 - Document some differences between mozilla::HashTable and PLDHashTable. r=Waldo 2018-07-26 20:15:55 +10:00
SimpleEnumerator.h Bug 1484373: Part 3 - Add ranged iterator wrapper for nsISimpleEnumerator. r=froydnj 2018-08-17 19:36:18 -07:00
StaticAtoms.py Bug 1483823 - Deduplicate system metric atoms. r=xidorn 2018-08-17 01:07:22 +00:00
StickyTimeDuration.h
Tokenizer.cpp Bug 1463786 - Make mozilla::Tokenizer work also with char16_t, r=froydnj 2018-05-31 03:40:00 +03:00
Tokenizer.h Bug 1463786 - Make mozilla::Tokenizer work also with char16_t, r=froydnj 2018-05-31 03:40:00 +03:00
moz.build Bug 1484496: Part 2 - Add common base class for all nsISimpleEnumerator implementations. r=froydnj 2018-08-18 14:22:47 -07:00
nsArray.cpp Bug 1484496: Part 4b - Add intrinsic type information to most nsSimpleEnumerators. r=froydnj 2018-08-18 21:06:32 -07:00
nsArray.h
nsArrayEnumerator.cpp Bug 1484496: Part 4b - Add intrinsic type information to most nsSimpleEnumerators. r=froydnj 2018-08-18 21:06:32 -07:00
nsArrayEnumerator.h Bug 1484496: Part 4b - Add intrinsic type information to most nsSimpleEnumerators. r=froydnj 2018-08-18 21:06:32 -07:00
nsArrayUtils.cpp
nsArrayUtils.h
nsAtom.h Bug 1483121 - Generate static atom hash in StaticAtoms.py. r=njn,emilio 2018-08-15 15:52:42 +10:00
nsAtomTable.cpp Bug 1483121 - Generate static atom hash in StaticAtoms.py. r=njn,emilio 2018-08-15 15:52:42 +10:00
nsAtomTable.h Bug 1447951 - Store nsDynamicAtom's chars after the end of the object. r=froydnj 2018-06-22 09:38:42 +10:00
nsBaseHashtable.h Bug 1465585: Switch from mozilla::Move to std::move. r=froydnj 2018-06-01 10:45:27 +02:00
nsCOMArray.cpp Bug 1407838 - Remove the remains of NS_Alloc/NS_Realloc/NS_Free. r=njn 2017-10-12 11:08:44 +09:00
nsCOMArray.h Bug 1465585: Switch from mozilla::Move to std::move. r=froydnj 2018-06-01 10:45:27 +02:00
nsCRT.cpp Bug 1427025 - Remove nsCRT::memmem. r=froydnj 2018-04-10 04:47:52 +10:00
nsCRT.h Bug 1453456 - Replace nsCRT::IsAscii{Alpha,Digit} with mfbt/TextUtils.h versions. r=froydnj 2018-04-12 20:19:30 -07:00
nsCharSeparatedTokenizer.h Bug 1374580 (part 3) - Remove ns{,C}Substring typedefs. r=froydnj. 2017-06-20 19:19:52 +10:00
nsCheapSets.h Bug 1469769 - Part 6: Replace non-failing NS_NOTREACHED with MOZ_ASSERT_UNREACHABLE. r=froydnj 2018-06-17 22:43:11 -07:00
nsClassHashtable.h Bug 1466168: Remove mozilla::Forward in favor of std::forward. r=froydnj 2018-06-02 09:33:26 +02:00
nsDataHashtable.h Bug 1465585: Switch from mozilla::Move to std::move. r=froydnj 2018-06-01 10:45:27 +02:00
nsDeque.cpp Bug 1378712 - Remove all trailing whitespaces r=Ehsan 2017-07-06 14:00:35 +02:00
nsDeque.h
nsEnumeratorUtils.cpp Bug 1484496: Part 3 - Fix nsISimpleEnumerator implementations with broken contracts. r=froydnj 2018-08-18 18:28:10 -07:00
nsEnumeratorUtils.h
nsExpirationTracker.h Bug 1453795 - XPCOM - Initialize member fields in classes/ structures. r=froydnj 2018-06-15 14:41:20 +03:00
nsGkAtoms.cpp Bug 1483121 - Generate static atom hash in StaticAtoms.py. r=njn,emilio 2018-08-15 15:52:42 +10:00
nsGkAtoms.h Bug 1483121 - Generate static atom hash in StaticAtoms.py. r=njn,emilio 2018-08-15 15:52:42 +10:00
nsHashKeys.h Backed out changeset 9035ff3757ac (bug 1415980) at request from froydnj on the suspicion that it's going to break MSVC builds when it gets merged to central. 2018-07-31 01:19:49 +03:00
nsHashPropertyBag.cpp Bug 1484496: Part 4b - Add intrinsic type information to most nsSimpleEnumerators. r=froydnj 2018-08-18 21:06:32 -07:00
nsHashPropertyBag.h
nsIArray.idl Bug 1484496: Part 4b - Add intrinsic type information to most nsSimpleEnumerators. r=froydnj 2018-08-18 21:06:32 -07:00
nsIArrayExtensions.idl Bug 1484496: Part 4b - Add intrinsic type information to most nsSimpleEnumerators. r=froydnj 2018-08-18 21:06:32 -07:00
nsIHashable.idl
nsIINIParser.idl Bug 1484844: Make nsINIParser mutable. r=froydnj 2017-10-12 14:20:57 -07:00
nsIMutableArray.idl Bug 1484496: Part 4b - Add intrinsic type information to most nsSimpleEnumerators. r=froydnj 2018-08-18 21:06:32 -07:00
nsINIParserImpl.cpp Bug 1484844: Make nsINIParser mutable. r=froydnj 2017-10-12 14:20:57 -07:00
nsINIParserImpl.h
nsIObserver.idl
nsIObserverService.idl
nsIPersistentProperties.h
nsIPersistentProperties2.idl Bug 1462138 - Part 1: Add a memory reporter for nsStringBundleService. r=erahm 2018-05-18 13:16:31 -07:00
nsIProperties.idl
nsIProperty.idl
nsIPropertyBag.idl
nsIPropertyBag2.idl
nsISerializable.idl Bug 1440808 - Cleanup error handling in nsXULPrototypeDocument::Read. r=mccr8 2018-02-22 11:33:20 -08:00
nsISimpleEnumerator.idl Bug 1484496: Part 4b - Add intrinsic type information to most nsSimpleEnumerators. r=froydnj 2018-08-18 21:06:32 -07:00
nsIStringEnumerator.idl
nsISupportsIterators.idl
nsISupportsPrimitives.idl
nsIVariant.idl Bug 1474369 - Part 7: Rename [array] to LegacyArray within xpt and xpidl, r=mccr8 2018-07-31 17:53:03 -04:00
nsIWindowsRegKey.idl
nsIWritablePropertyBag.idl
nsIWritablePropertyBag2.idl
nsInterfaceHashtable.h Bug 1465585: Switch from mozilla::Move to std::move. r=froydnj 2018-06-01 10:45:27 +02:00
nsJSThingHashtable.h
nsMathUtils.h
nsObserverList.cpp Bug 1484496: Part 3 - Fix nsISimpleEnumerator implementations with broken contracts. r=froydnj 2018-08-18 18:28:10 -07:00
nsObserverList.h Bug 1484496: Part 4b - Add intrinsic type information to most nsSimpleEnumerators. r=froydnj 2018-08-18 21:06:32 -07:00
nsObserverService.cpp Bug 1464252 - Remove global observers functionality from the observer service; r=froydnj 2018-05-24 23:58:31 +02:00
nsObserverService.h
nsPersistentProperties.cpp Bug 1484496: Part 4b - Add intrinsic type information to most nsSimpleEnumerators. r=froydnj 2018-08-18 21:06:32 -07:00
nsPersistentProperties.h Bug 1462138 - Part 1: Add a memory reporter for nsStringBundleService. r=erahm 2018-05-18 13:16:31 -07:00
nsPointerHashKeys.h Backed out changeset 9035ff3757ac (bug 1415980) at request from froydnj on the suspicion that it's going to break MSVC builds when it gets merged to central. 2018-07-31 01:19:49 +03:00
nsProperties.cpp Bug 1376498 part 2 - Use plain Remove(key) in some places instead of Lookup(key).Remove() for simplicity. r=froydnj 2017-07-05 02:01:44 +02:00
nsProperties.h
nsQuickSort.cpp
nsQuickSort.h
nsRefPtrHashtable.h Bug 1465585: Switch from mozilla::Move to std::move. r=froydnj 2018-06-01 10:45:27 +02:00
nsSimpleEnumerator.cpp Bug 1484496: Part 4b - Add intrinsic type information to most nsSimpleEnumerators. r=froydnj 2018-08-18 21:06:32 -07:00
nsSimpleEnumerator.h Bug 1484496: Part 4b - Add intrinsic type information to most nsSimpleEnumerators. r=froydnj 2018-08-18 21:06:32 -07:00
nsStaticAtomUtils.h Bug 1483449 - Simplify nsStaticAtomUtils::Lookup. r=njn 2018-08-16 11:40:02 +10:00
nsStaticNameTable.cpp Bug 1475461 - part 2: Make callers of PLDHashTable::Search() const methods if possible r=Ehsan 2018-07-13 19:01:53 +09:00
nsStaticNameTable.h Bug 1475461 - part 2: Make callers of PLDHashTable::Search() const methods if possible r=Ehsan 2018-07-13 19:01:53 +09:00
nsStringEnumerator.cpp Bug 1484496: Part 4b - Add intrinsic type information to most nsSimpleEnumerators. r=froydnj 2018-08-18 21:06:32 -07:00
nsStringEnumerator.h
nsSupportsPrimitives.cpp Bug 1409227 (part 4) - Replace nsMemory::Clone(id, sizeof(nsID)) with nsID::Clone(id). r=mccr8. 2017-10-18 10:39:20 +11:00
nsSupportsPrimitives.h
nsTArray-inl.h Bug 1473804: Don't lie to AutoTArray::EnsureCapacity. r=erahm 2018-07-17 10:23:47 +02:00
nsTArray.cpp Bug 1460733 - Rename nsTArrayHeader::sEmptyHdr to extern "C" { sEmptyTArrayHeader } so that thin-vec can link with it. r=froydnj 2018-05-10 16:37:27 -04:00
nsTArray.h Bug 1479996 - Combine nsTArray::IndexOf and element access into lambda-friendly functions - r=froydnj 2018-08-28 22:04:09 +00:00
nsTArrayForwardDeclare.h
nsTHashtable.h Bug 1477626 - Document some differences between mozilla::HashTable and PLDHashTable. r=Waldo 2018-07-26 20:15:55 +10:00
nsTObserverArray.cpp Bug 1457813 - Part 2: Replace non-asserting NS_PRECONDITIONs with MOZ_ASSERTs. r=froydnj 2018-04-28 12:50:58 -07:00
nsTObserverArray.h Bug 1385533 - Reserve space for one pointer in the mMutationObservers array on node slots; r=smaug 2017-07-31 17:12:38 -04:00
nsTPriorityQueue.h
nsVariant.cpp Bug 1402247 - Use encoding_rs for XPCOM string encoding conversions. r=Nika,erahm,froydnj. 2018-08-14 14:43:42 +03:00
nsVariant.h Bug 1453795 - XPCOM - Initialize member fields in classes/ structures. r=froydnj 2018-06-15 14:41:20 +03:00
nsWhitespaceTokenizer.h Bug 1374580 (part 3) - Remove ns{,C}Substring typedefs. r=froydnj. 2017-06-20 19:19:52 +10:00
nsWindowsRegKey.cpp Bug 1353593 - Part 2: Remove wwc functions. r=froydnj 2017-06-12 16:20:49 -07:00
nsWindowsRegKey.h