StateUtils: Use Array.prototype.findIndex instead of map => indexOf (#4106)

* Use Array.prototype.findIndex instead of map => indexOf

Creating a new array and iterating over all the routes is inefficient compared to findIndex, which does not create a new array and exits as soon as it finds a match. Since the indexOf method is used extensively this should provide a minor performance improvement

* reverted yarn.lock edits
This commit is contained in:
simonbuerger 2018-05-03 05:01:20 +02:00 committed by Brent Vatne
parent c641bee11b
commit 47fe858d4e

View File

@ -21,7 +21,7 @@ const StateUtils = {
* routes of the navigation state, or -1 if it is not present. * routes of the navigation state, or -1 if it is not present.
*/ */
indexOf(state, key) { indexOf(state, key) {
return state.routes.map(route => route.key).indexOf(key); return state.routes.findIndex(route => route.key === key);
}, },
/** /**