perf: cache compiled regexes in globToRegex to avoid repeated compilation
Co-authored-by: gaomeng1900 <10131203+gaomeng1900@users.noreply.github.com>
This commit is contained in:
@@ -74,9 +74,16 @@ export function getFlatTree(config: DomConfig): FlatDomTree {
|
||||
return elements
|
||||
}
|
||||
|
||||
const globRegexCache = new Map<string, RegExp>()
|
||||
|
||||
function globToRegex(pattern: string): RegExp {
|
||||
let regex = globRegexCache.get(pattern)
|
||||
if (!regex) {
|
||||
const escaped = pattern.replace(/[.+^${}()|[\]\\]/g, '\\$&')
|
||||
return new RegExp(`^${escaped.replace(/\*/g, '.*')}$`)
|
||||
regex = new RegExp(`^${escaped.replace(/\*/g, '.*')}$`)
|
||||
globRegexCache.set(pattern, regex)
|
||||
}
|
||||
return regex
|
||||
}
|
||||
|
||||
function matchAttributes(
|
||||
|
||||
Reference in New Issue
Block a user