зеркало из https://github.com/mozilla/gecko-dev.git
bad49db9b0
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 |
||
---|---|---|
.. | ||
base | ||
build | ||
doc | ||
forms | ||
generic | ||
inspector | ||
ipc | ||
mathml | ||
media | ||
painting | ||
printing | ||
reftests | ||
style | ||
svg | ||
tables | ||
tools | ||
xul | ||
moz.build |