Open Bug 1486941 Opened Last year

Replace `nsTArray::IndexOf(...) != NoIndex` patterns with `nsTArray::Contains`

Categories

(Core :: XPCOM, enhancement)

63 Branch
enhancement
Not set

Tracking

()

Tracking Status
firefox63 --- affected

People

(Reporter: gerald, Unassigned)

References

Details

There are quite a few places where some code wants to know if an array contains a particular element, and it is done with something like `array.IndexOf(element) != decltype(array)::NoIndex`.

Instead, these searches should now be done with `array.Contains(element)`.
The main reasons are:
- `Contains` is now more efficient than `IndexOf!=NoIndex`, as it doesn't compute an index and then compares it to NoIndex; instead it directly returns true when the element is found, or false otherwise. See bug 1479996 for details.
- "Contains" is shorter, and conveys a clearer intent than "Find an index and compare to no-index".

Sometimes the IndexOf value is compared to NoIndex, and then reused to actually work on the element. This is generally fine to keep, as the index computation is not wasted; a subset could possibly be replaced with nsTArray::ApplyIf, TBD.
You need to log in before you can comment on or make changes to this bug.