Skip to content

Commit

Permalink
perf(runtime-core): optimize the performance of getTypeIndex (#3206)
Browse files Browse the repository at this point in the history
  • Loading branch information
edison1105 authored Mar 30, 2021
1 parent c8df618 commit 2e50acf
Showing 1 changed file with 1 addition and 5 deletions.
6 changes: 1 addition & 5 deletions packages/runtime-core/src/componentProps.ts
Original file line number Diff line number Diff line change
Expand Up @@ -456,11 +456,7 @@ function getTypeIndex(
expectedTypes: PropType<any> | void | null | true
): number {
if (isArray(expectedTypes)) {
for (let i = 0, len = expectedTypes.length; i < len; i++) {
if (isSameType(expectedTypes[i], type)) {
return i
}
}
return expectedTypes.findIndex(t => isSameType(t, type))

This comment has been minimized.

Copy link
@Smrtnyk

Smrtnyk Mar 30, 2021

isSameType.bind(null, type) would be even faster than recreating the callback on iteration
You would need to switch the params in function signature though

I did some research before and turned out bind was 10 factor faster than higher order functions

} else if (isFunction(expectedTypes)) {
return isSameType(expectedTypes, type) ? 0 : -1
}
Expand Down

0 comments on commit 2e50acf

Please sign in to comment.