gecko-dev/xpcom
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
..
base Bug 1484373: Part 2b - Add cycle collection helpers for Tuple types. r=smaug 2018-08-19 17:43:29 -07:00
build Merge inbound to mozilla-central. a=merge 2018-08-29 00:58:21 +03:00
components Bug 1484496: Part 4b - Add intrinsic type information to most nsSimpleEnumerators. r=froydnj 2018-08-18 21:06:32 -07:00
doc
ds Bug 1479996 - Combine nsTArray::IndexOf and element access into lambda-friendly functions - r=froydnj 2018-08-28 22:04:09 +00:00
glue Bug 1402247 - Use encoding_rs for XPCOM string encoding conversions. r=Nika,erahm,froydnj. 2018-08-14 14:43:42 +03:00
idl-parser Bug 1484496: Part 1 - Add support for symbol properties to XPIDL. r=nika 2018-08-21 14:08:35 -07:00
io Bug 1486528 - Remove some unnecessary nsIMemory imports. r=njn 2018-08-27 16:38:18 +02:00
libxpt/xptcall Bug 1403959, part 2 - Automatically generated eslint fixes. r=froydnj 2017-09-28 15:49:04 -07:00
reflect Bug 1484496: Part 1 - Add support for symbol properties to XPIDL. r=nika 2018-08-21 14:08:35 -07:00
rust Bug 1482011 - Make Bench_Cpp_MozHashSet more idiomatic. r=froydnj 2018-08-14 08:52:38 +10:00
string Bug 1482828 - Introduce C++ analogs of Rust's nsA[C]StringBulkWriteHandle. r=froydnj 2018-08-28 16:42:26 +00:00
system Bug 1348273 - Convert crash annotations into a machine-readable list of constants; r=ted.mielczarek,njn,dholbert,mak,cpearce,mcmanus,froydnj,Dexter,jrmuizel,jchen,jimm,bz,surkov 2018-07-05 15:42:11 +02:00
tests Bug 1479996 - Combine nsTArray::IndexOf and element access into lambda-friendly functions - r=froydnj 2018-08-28 22:04:09 +00:00
threads Bug 1459212 - Save memory reports for use in crash reports when low on memory r=dmajor,mccr8 2018-08-20 21:53:27 +00:00
typelib Bug 1471620 - Skip python-tests locally that don't run with python 3 in CI r=davehunt 2018-06-27 11:10:02 -04:00
windbgdlg Bug 1090497 - Re-enable warnings as errors on clang-cl. r=froydnj 2018-07-31 22:10:07 +09:00
xpidl Bug 1459721 - part 7 - remove dist_idl install manifest; r=chmanchester 2018-05-15 10:05:23 -04:00
moz.build Bug 1444745 - Part 1: Clear out xptinfo and typelib to make way for the this patch, r=mccr8 2018-04-17 19:20:50 -04:00
xpcom-config.h.in
xpcom-private.h.in Bug 1423846 - Remove configure script checks for iconv and mbrtowc/tcrtomb. r=glandium 2017-12-07 14:06:53 +02:00