gecko-dev/layout
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 1479996 - Combine nsTArray::IndexOf and element access into lambda-friendly functions - r=froydnj 2018-08-28 22:04:09 +00:00
build Bug 1485871 - Remove some unused XPCOM registrations for editor; r=masayuki 2018-08-24 09:33:18 -04:00
doc Bug 1483090 - Rename StyleUserInterface to StyleUI. r=emilio 2018-08-14 08:37:37 +00:00
forms Backed out changeset 69faa23050d9 (bug 1412179) for landing without first patch 2018-08-24 18:32:02 +03:00
generic Merge inbound to mozilla-central a=merge 2018-08-25 01:08:22 +03:00
inspector Bug 1246764 - Part 2: Define path() for clip-path. r=emilio 2018-08-24 11:37:53 -07:00
ipc Bug 1483090 - Rename StyleUserInterface to StyleUI. r=emilio 2018-08-14 08:37:37 +00:00
mathml Bug 1483394: Remove unneeded #includes of nsContentUtils.h in /layout. r=TYLin 2018-08-15 07:04:43 +00:00
media
painting Bug 1459065 - Clip filter effects at the stacking context level. r=mstange 2018-08-28 15:42:14 +00:00
printing Bug 1482665 Part 5 - Remove nsDeviceContext::AppUnitsPerCSSInch() and replace it with mozilla::AppUnitsPerCSSInch(). r=dholbert 2018-08-13 14:29:30 -07:00
reftests Bug 1459065 - Clip filter effects at the stacking context level. r=mstange 2018-08-28 15:42:14 +00:00
style Backed out changeset a47f6d2d38a4 (bug 1486536) for failing at tests/layout/style/crashtests/1486536.html 2018-08-28 18:59:06 +03:00
svg Bug 1246764 - Part 4: Rename mask flag and function name of xxxBasicShape to xxxBasicShapeOrPath. r=jwatt 2018-08-24 11:37:57 -07:00
tables Bug 1482665 Part 2 - Remove nsPresContext::AppUnitsPerCSSPixel() and replace it with mozilla::AppUnitsPerCSSPixel(). r=dholbert 2018-08-13 14:29:28 -07:00
tools Bug 1486399 - Teach the layout debugger about relative URIs. r=mats 2018-08-27 15:35:56 +00:00
xul Backed out changeset 641eedc51cc0 (bug 1453953)for reftest failures on tests/layout/reftests/text-shadow/basic.xul 2018-08-26 00:51:46 +03:00
moz.build