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
|
import Quickshell
|
||||||
|
|
||||||
Singleton {
|
Singleton {
|
||||||
|
property var _regexCache: ({})
|
||||||
|
|
||||||
function testRegexList(filterList: list<string>, target: string): bool {
|
function testRegexList(filterList: list<string>, target: string): bool {
|
||||||
const regexChecker = /^\^.*\$$/;
|
const regexChecker = /^\^.*\$$/;
|
||||||
for (const filter of filterList) {
|
for (const filter of filterList) {
|
||||||
// If filter is a regex
|
|
||||||
if (regexChecker.test(filter)) {
|
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;
|
return true;
|
||||||
} else {
|
} else {
|
||||||
if (filter === target)
|
if (filter === target)
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue