Skip to content

Commit c7987f4

Browse files
authored
Use regex.test(str) instead of str.match(regex) (#152)
This method returns a boolean so it should be faster and more memory efficient. In order to make this work, I needed to remove the global flag from the regexes, because that makes the regexes mutable when run multiple times. Since these are only used to test for any match, and not for any matching groups or in any other way, we don't need this flag.
1 parent 4bca1e1 commit c7987f4

File tree

2 files changed

+8
-4
lines changed

2 files changed

+8
-4
lines changed

src/index.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ function isPathReactClass(path, globalOptions) {
1919
return true
2020
}
2121

22-
if (node && matchers && node.name.match(matchers)) {
22+
if (node && matchers && matchers.test(node.name)) {
2323
return true
2424
}
2525

@@ -97,13 +97,13 @@ export default function(api) {
9797
let classNameMatchers
9898

9999
if (state.opts.ignoreFilenames) {
100-
ignoreFilenames = new RegExp(state.opts.ignoreFilenames.join('|'), 'gi')
100+
ignoreFilenames = new RegExp(state.opts.ignoreFilenames.join('|'), 'i')
101101
} else {
102102
ignoreFilenames = undefined
103103
}
104104

105105
if (state.opts.classNameMatchers) {
106-
classNameMatchers = new RegExp(state.opts.classNameMatchers.join('|'), 'g')
106+
classNameMatchers = new RegExp(state.opts.classNameMatchers.join('|'))
107107
} else {
108108
classNameMatchers = undefined
109109
}

src/remove.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,11 @@ function isInside(scope, regex) {
1212
return true
1313
}
1414

15-
return filename.match(regex) !== null
15+
if (!regex) {
16+
return false
17+
}
18+
19+
return regex.test(filename)
1620
}
1721

1822
// Remove a specific path.

0 commit comments

Comments
 (0)