perf: replace Map/Set with WeakMap/WeakSet (#8549)

This commit is contained in:
丶远方 2023-10-20 17:11:52 +08:00 committed by GitHub
parent 4162311efd
commit 712f96d6ac
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 8 additions and 6 deletions

View 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),

View File

@ -227,7 +227,7 @@ export function createAppAPI<HostElement>(
})
}
const installedPlugins = new Set()
const installedPlugins = new WeakSet()
let isMounted = false

View 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)) {

View 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]