Skip to content

Commit ae6fba9

Browse files
committedNov 25, 2023
perf: optimize makeMap
1 parent 81e941d commit ae6fba9

File tree

1 file changed

+4
-6
lines changed

1 file changed

+4
-6
lines changed
 

‎packages/shared/src/makeMap.ts

+4-6
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,8 @@ export function makeMap(
99
str: string,
1010
expectsLowerCase?: boolean
1111
): (key: string) => boolean {
12-
const map: Record<string, boolean> = Object.create(null)
13-
const list: Array<string> = str.split(',')
14-
for (let i = 0; i < list.length; i++) {
15-
map[list[i]] = true
16-
}
17-
return expectsLowerCase ? val => !!map[val.toLowerCase()] : val => !!map[val]
12+
const set = new Set(str.split(','))
13+
return expectsLowerCase
14+
? val => set.has(val.toLowerCase())
15+
: val => set.has(val)
1816
}

0 commit comments

Comments
 (0)
Please sign in to comment.