mirror of https://github.com/gorhill/uBlock.git
code review: regex perf as per https://www.loggly.com/blog/five-invaluable-techniques-to-improve-regex-performance/
This commit is contained in:
parent
03093b91eb
commit
dd394ebba5
|
@ -193,9 +193,10 @@ var strToRegex = function(s, anchor, flags) {
|
||||||
return alwaysTruePseudoRegex;
|
return alwaysTruePseudoRegex;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// https://www.loggly.com/blog/five-invaluable-techniques-to-improve-regex-performance/
|
||||||
// https://developer.mozilla.org/en/docs/Web/JavaScript/Guide/Regular_Expressions
|
// https://developer.mozilla.org/en/docs/Web/JavaScript/Guide/Regular_Expressions
|
||||||
var reStr = s.replace(/[.+?^${}()|[\]\\]/g, '\\$&')
|
var reStr = s.replace(/[.+?^${}()|[\]\\]/g, '\\$&')
|
||||||
.replace(/\*/g, '.*');
|
.replace(/\*/g, '[^ ]*?');
|
||||||
|
|
||||||
if ( anchor < 0 ) {
|
if ( anchor < 0 ) {
|
||||||
reStr = '^' + reStr;
|
reStr = '^' + reStr;
|
||||||
|
|
Loading…
Reference in New Issue