]> git.ipfire.org Git - thirdparty/vuejs/core.git/commitdiff
perf: replace Map/Set with WeakMap/WeakSet (#8549)
author丶远方 <yangpanteng@gmail.com>
Fri, 20 Oct 2023 09:11:52 +0000 (17:11 +0800)
committerGitHub <noreply@github.com>
Fri, 20 Oct 2023 09:11:52 +0000 (17:11 +0800)
packages/compiler-core/src/transform.ts
packages/runtime-core/src/apiCreateApp.ts
packages/runtime-core/src/compat/componentAsync.ts
packages/runtime-core/src/compat/componentFunctional.ts

index 4d9e8c6ed49d57102b3140abe59d6b207dd4f387..d26c11bba2066cb57ad82c32bd94ceca567caa1f 100644 (file)
@@ -117,7 +117,7 @@ export interface TransformContext
   removeIdentifiers(exp: ExpressionNode | string): void
   hoist(exp: string | JSChildNode | ArrayExpression): SimpleExpressionNode
   cache<T extends JSChildNode>(exp: T, isVNode?: boolean): CacheExpression | T
-  constantCache: Map<TemplateChildNode, ConstantTypes>
+  constantCache: WeakMap<TemplateChildNode, ConstantTypes>
 
   // 2.x Compat only
   filters?: Set<string>
@@ -181,7 +181,7 @@ export function createTransformContext(
     directives: new Set(),
     hoists: [],
     imports: [],
-    constantCache: new Map(),
+    constantCache: new WeakMap(),
     temps: 0,
     cached: 0,
     identifiers: Object.create(null),
index c5ac9d68a5224c0df476b8582d5d8a3a63b9f554..8e4ab1f3aa0ca71998e503147fee96d7ea93177f 100644 (file)
@@ -227,7 +227,7 @@ export function createAppAPI<HostElement>(
       })
     }
 
-    const installedPlugins = new Set()
+    const installedPlugins = new WeakSet()
 
     let isMounted = false
 
index 0a0dee72b634c1d673850de3c9b78215ee0aa1fd..5b2ac22c23398615f5d1f99e0ed791931b960260 100644 (file)
@@ -18,7 +18,10 @@ type LegacyAsyncComponent = (
   reject?: (reason?: any) => void
 ) => LegacyAsyncReturnValue | undefined
 
-const normalizedAsyncComponentMap = new Map<LegacyAsyncComponent, Component>()
+const normalizedAsyncComponentMap = new WeakMap<
+  LegacyAsyncComponent,
+  Component
+>()
 
 export function convertLegacyAsyncComponent(comp: LegacyAsyncComponent) {
   if (normalizedAsyncComponentMap.has(comp)) {
index 1b1146bbab94ae8c6585c0edec2769d2f4c1194b..90d24e1ba734e5bf62b591273e4adfd2fb342aa1 100644 (file)
@@ -8,11 +8,10 @@ import { InternalSlots } from '../componentSlots'
 import { getCompatListeners } from './instanceListeners'
 import { compatH } from './renderFn'
 
-const normalizedFunctionalComponentMap = new Map<
+const normalizedFunctionalComponentMap = new WeakMap<
   ComponentOptions,
   FunctionalComponent
 >()
-
 export const legacySlotProxyHandlers: ProxyHandler<InternalSlots> = {
   get(target, key: string) {
     const slot = target[key]