perf: optimize makeMap

This commit is contained in:
Evan You 2023-11-16 17:02:17 +08:00
parent 81e941da5b
commit ae6fba9495
1 changed files with 4 additions and 6 deletions

View File

@ -9,10 +9,8 @@ export function makeMap(
str: string,
expectsLowerCase?: boolean
): (key: string) => boolean {
const map: Record<string, boolean> = Object.create(null)
const list: Array<string> = str.split(',')
for (let i = 0; i < list.length; i++) {
map[list[i]] = true
}
return expectsLowerCase ? val => !!map[val.toLowerCase()] : val => !!map[val]
const set = new Set(str.split(','))
return expectsLowerCase
? val => set.has(val.toLowerCase())
: val => set.has(val)
}