From 2e50acfbb89c29a071765d7f3967d2ccaf14f375 Mon Sep 17 00:00:00 2001 From: edison Date: Tue, 30 Mar 2021 22:53:14 +0800 Subject: [PATCH] perf(runtime-core): optimize the performance of getTypeIndex (#3206) --- 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 3ea727ddcc3..476fba887dc 100644 --- a/packages/runtime-core/src/componentProps.ts +++ b/packages/runtime-core/src/componentProps.ts @@ -456,11 +456,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 }