Merge pull request #175 from alibaba/copilot/sub-pr-173-again
perf(page-controller): cache compiled regexes in `globToRegex`
This commit is contained in:
@@ -74,9 +74,16 @@ export function getFlatTree(config: DomConfig): FlatDomTree {
|
|||||||
return elements
|
return elements
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const globRegexCache = new Map<string, RegExp>()
|
||||||
|
|
||||||
function globToRegex(pattern: string): RegExp {
|
function globToRegex(pattern: string): RegExp {
|
||||||
|
let regex = globRegexCache.get(pattern)
|
||||||
|
if (!regex) {
|
||||||
const escaped = pattern.replace(/[.+^${}()|[\]\\]/g, '\\$&')
|
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(
|
function matchAttributes(
|
||||||
|
|||||||
Reference in New Issue
Block a user