From: 丶远方 Date: Fri, 20 Oct 2023 09:11:52 +0000 (+0800) Subject: perf: replace Map/Set with WeakMap/WeakSet (#8549) X-Git-Tag: v3.3.6~6 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=712f96d6ac4d3d984732cba448cb84624daba850;p=thirdparty%2Fvuejs%2Fcore.git perf: replace Map/Set with WeakMap/WeakSet (#8549) --- diff --git a/packages/compiler-core/src/transform.ts b/packages/compiler-core/src/transform.ts index 4d9e8c6ed4..d26c11bba2 100644 --- a/packages/compiler-core/src/transform.ts +++ b/packages/compiler-core/src/transform.ts @@ -117,7 +117,7 @@ export interface TransformContext removeIdentifiers(exp: ExpressionNode | string): void hoist(exp: string | JSChildNode | ArrayExpression): SimpleExpressionNode cache(exp: T, isVNode?: boolean): CacheExpression | T - constantCache: Map + constantCache: WeakMap // 2.x Compat only filters?: Set @@ -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), diff --git a/packages/runtime-core/src/apiCreateApp.ts b/packages/runtime-core/src/apiCreateApp.ts index c5ac9d68a5..8e4ab1f3aa 100644 --- a/packages/runtime-core/src/apiCreateApp.ts +++ b/packages/runtime-core/src/apiCreateApp.ts @@ -227,7 +227,7 @@ export function createAppAPI( }) } - const installedPlugins = new Set() + const installedPlugins = new WeakSet() let isMounted = false diff --git a/packages/runtime-core/src/compat/componentAsync.ts b/packages/runtime-core/src/compat/componentAsync.ts index 0a0dee72b6..5b2ac22c23 100644 --- a/packages/runtime-core/src/compat/componentAsync.ts +++ b/packages/runtime-core/src/compat/componentAsync.ts @@ -18,7 +18,10 @@ type LegacyAsyncComponent = ( reject?: (reason?: any) => void ) => LegacyAsyncReturnValue | undefined -const normalizedAsyncComponentMap = new Map() +const normalizedAsyncComponentMap = new WeakMap< + LegacyAsyncComponent, + Component +>() export function convertLegacyAsyncComponent(comp: LegacyAsyncComponent) { if (normalizedAsyncComponentMap.has(comp)) { diff --git a/packages/runtime-core/src/compat/componentFunctional.ts b/packages/runtime-core/src/compat/componentFunctional.ts index 1b1146bbab..90d24e1ba7 100644 --- a/packages/runtime-core/src/compat/componentFunctional.ts +++ b/packages/runtime-core/src/compat/componentFunctional.ts @@ -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 = { get(target, key: string) { const slot = target[key]