strings: cache compiled RegExp objects

This commit is contained in:
2 * r + 2 * t 2026-03-12 22:22:45 +11:00
parent 8812073ab1
commit 11b30a0f69

View file

@ -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)