Permalink
Browse files

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
  • Loading branch information...
simonbuerger authored and brentvatne committed May 3, 2018
1 parent c641bee commit 47fe858d4ec339d2b1f4b96f3a5444aed8f6f900
Showing with 1 addition and 1 deletion.
  1. +1 −1 src/StateUtils.js
@@ -21,7 +21,7 @@ const StateUtils = {
* routes of the navigation state, or -1 if it is not present.
*/
indexOf(state, key) {
return state.routes.map(route => route.key).indexOf(key);
return state.routes.findIndex(route => route.key === key);
},
/**

0 comments on commit 47fe858

Please sign in to comment.