perf(runtime-core): optimize the performance of getTypeIndex (#3206)

This commit is contained in:
edison 2021-03-30 22:53:14 +08:00 committed by GitHub
parent c8df6185fe
commit 2e50acfbb8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -456,11 +456,7 @@ function getTypeIndex(
expectedTypes: PropType<any> | void | null | true expectedTypes: PropType<any> | void | null | true
): number { ): number {
if (isArray(expectedTypes)) { if (isArray(expectedTypes)) {
for (let i = 0, len = expectedTypes.length; i < len; i++) { return expectedTypes.findIndex(t => isSameType(t, type))
if (isSameType(expectedTypes[i], type)) {
return i
}
}
} else if (isFunction(expectedTypes)) { } else if (isFunction(expectedTypes)) {
return isSameType(expectedTypes, type) ? 0 : -1 return isSameType(expectedTypes, type) ? 0 : -1
} }