]> git.ipfire.org Git - thirdparty/vuejs/core.git/commitdiff
perf(runtime-core): optimize the performance of getTypeIndex (#3206)
authoredison <daiwei521@126.com>
Tue, 30 Mar 2021 14:53:14 +0000 (22:53 +0800)
committerGitHub <noreply@github.com>
Tue, 30 Mar 2021 14:53:14 +0000 (10:53 -0400)
packages/runtime-core/src/componentProps.ts

index 3ea727ddcc3101e381ec4ebc6dfa6e7de3a2855f..476fba887dce8a156ebe219f196439f5e703b83d 100644 (file)
@@ -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))
   } else if (isFunction(expectedTypes)) {
     return isSameType(expectedTypes, type) ? 0 : -1
   }