From 28d943a3d5629552600a99d2f5c39fc559a86cc0 Mon Sep 17 00:00:00 2001 From: daiwei Date: Tue, 9 Feb 2021 20:19:41 +0800 Subject: [PATCH] perf(runtime-core): optimize the performance of getTypeIndex --- packages/runtime-core/src/componentProps.ts | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/packages/runtime-core/src/componentProps.ts b/packages/runtime-core/src/componentProps.ts index f30c238e9da..6cc0e7cf291 100644 --- a/packages/runtime-core/src/componentProps.ts +++ b/packages/runtime-core/src/componentProps.ts @@ -446,11 +446,7 @@ function getTypeIndex( expectedTypes: PropType | 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)) } else if (isFunction(expectedTypes)) { return isSameType(expectedTypes, type) ? 0 : -1 }