Skip to content

Commit

Permalink
Optimize string.match(regex) to regex.test(string)
Browse files Browse the repository at this point in the history
  • Loading branch information
gregmagolan committed May 14, 2019
1 parent a8397c3 commit 693b58e
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 3 deletions.
2 changes: 1 addition & 1 deletion internal/node/generate_build_file.js
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ function listFiles(rootDir, subDir = '') {
function filterFilesForFilegroup(files, allowedExts = [], excludedExts = []) {
// Files with spaces (\x20) or unicode characters (<\x20 && >\x7E) are not allowed in
// Bazel runfiles. See https://github.com/bazelbuild/bazel/issues/4327
files = files.filter(f => !f.match(/[^\x21-\x7E]/));
files = files.filter(f => !/[^\x21-\x7E]/.test(f));
if (allowedExts.length) {
const allowNoExts = allowedExts.includes('');
files = files.filter(f => {
Expand Down
4 changes: 2 additions & 2 deletions internal/npm_install/generate_build_file.js
Original file line number Diff line number Diff line change
Expand Up @@ -468,7 +468,7 @@ function listFiles(rootDir, subDir = '') {
[])
// Files with spaces (\x20) or unicode characters (<\x20 && >\x7E) are not allowed in
// Bazel runfiles. See https://github.com/bazelbuild/bazel/issues/4327
.filter(f => !f.match(/[^\x21-\x7E]/))
.filter(f => !/[^\x21-\x7E]/.test(f))
// We return a sorted array so that the order of files
// is the same regardless of platform
.sort();
Expand Down Expand Up @@ -553,7 +553,7 @@ function parsePackage(p) {
pkg._name = pkg._dir.split('/').pop();

// Keep track of whether or not this is a nested package
pkg._isNested = p.match(/\/node_modules\//);
pkg._isNested = /\/node_modules\//.test(p);

// List all the files in the npm package for later use
pkg._files = listFiles(p);
Expand Down

0 comments on commit 693b58e

Please sign in to comment.