Caching added for Magic regexes

This commit is contained in:
n1073645 2020-03-12 14:45:40 +00:00
parent 570a84b67a
commit 5b5105c864
1 changed files with 4 additions and 5 deletions

View File

@ -36,10 +36,10 @@ class Magic {
const matches = []; const matches = [];
for (let i = 0; i < opPatterns.length; i++) { for (let i = 0; i < opPatterns.length; i++) {
const pattern = opPatterns[i], const pattern = opPatterns[i];
regex = new RegExp(pattern.match, pattern.flags);
if (regex.test(this.inputStr)) {
if (pattern.match.test(this.inputStr)) {
matches.push(pattern); matches.push(pattern);
} }
} }
@ -522,8 +522,7 @@ class Magic {
OperationConfig[op].input.regex.forEach(pattern => { OperationConfig[op].input.regex.forEach(pattern => {
opCriteria.regex.push({ opCriteria.regex.push({
op: op, op: op,
match: pattern.match, match: new RegExp(pattern.match, pattern.flags),
flags: pattern.flags,
args: pattern.args, args: pattern.args,
useful: pattern.useful || false useful: pattern.useful || false
}); });