Skip to content

Commit

Permalink
refactor(lib/utils.js): Replace hasMatchingExtname implementation
Browse files Browse the repository at this point in the history
Swapped out the `RegExp.test` implementation for `Array.some` one, providing ~3.5x speedup.
  • Loading branch information
plroebuck committed Feb 13, 2019
1 parent b82d65d commit 6f96594
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions lib/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -528,8 +528,10 @@ exports.canonicalize = function canonicalize(value, stack, typeHint) {
* hasMatchingExtname('foo.html', ['js', 'css']); // => false
*/
function hasMatchingExtname(pathname, exts) {
var re = new RegExp('\\.(?:' + exts.join('|') + ')$');
return re.test(path.extname(pathname));
var suffix = path.extname(pathname).slice(1);
return exts.some(function(element) {
return suffix === element;
});
}

/**
Expand Down

0 comments on commit 6f96594

Please sign in to comment.