Skip to content

Commit

Permalink
Cache keyword regexps
Browse files Browse the repository at this point in the history
Closes #1233
  • Loading branch information
marijnh committed Aug 11, 2023
1 parent 38b7af4 commit c5b8cae
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion acorn/src/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,10 @@ export const isArray = Array.isArray || ((obj) => (
toString.call(obj) === "[object Array]"
))

const regexpCache = Object.create(null)

export function wordsRegexp(words) {
return new RegExp("^(?:" + words.replace(/ /g, "|") + ")$")
return regexpCache[words] || (regexpCache[words] = new RegExp("^(?:" + words.replace(/ /g, "|") + ")$"))
}

export function codePointToString(code) {
Expand Down

0 comments on commit c5b8cae

Please sign in to comment.