Skip to content

Commit

Permalink
perf: optimize makeMap
Browse files Browse the repository at this point in the history
  • Loading branch information
yyx990803 committed Nov 25, 2023
1 parent 81e941d commit ae6fba9
Showing 1 changed file with 4 additions and 6 deletions.
10 changes: 4 additions & 6 deletions packages/shared/src/makeMap.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}

0 comments on commit ae6fba9

Please sign in to comment.