strings: cache compiled RegExp objects
This commit is contained in:
parent
8812073ab1
commit
11b30a0f69
1 changed files with 8 additions and 2 deletions
|
|
@ -3,12 +3,18 @@ pragma Singleton
|
|||
import Quickshell
|
||||
|
||||
Singleton {
|
||||
property var _regexCache: ({})
|
||||
|
||||
function testRegexList(filterList: list<string>, target: string): bool {
|
||||
const regexChecker = /^\^.*\$$/;
|
||||
for (const filter of filterList) {
|
||||
// If filter is a regex
|
||||
if (regexChecker.test(filter)) {
|
||||
if ((new RegExp(filter)).test(target))
|
||||
let re = _regexCache[filter];
|
||||
if (!re) {
|
||||
re = new RegExp(filter);
|
||||
_regexCache[filter] = re;
|
||||
}
|
||||
if (re.test(target))
|
||||
return true;
|
||||
} else {
|
||||
if (filter === target)
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue