perf: using a _isVNode field is faster than a weakset
This commit is contained in:
parent
1b90fff294
commit
7f06981f7c
@ -55,6 +55,7 @@ export type NormalizedChildren<HostNode = any, HostElement = any> =
|
|||||||
| null
|
| null
|
||||||
|
|
||||||
export interface VNode<HostNode = any, HostElement = any> {
|
export interface VNode<HostNode = any, HostElement = any> {
|
||||||
|
_isVNode: true
|
||||||
type: VNodeTypes
|
type: VNodeTypes
|
||||||
props: Record<any, any> | null
|
props: Record<any, any> | null
|
||||||
key: string | number | null
|
key: string | number | null
|
||||||
@ -124,10 +125,8 @@ export function createBlock(
|
|||||||
return vnode
|
return vnode
|
||||||
}
|
}
|
||||||
|
|
||||||
const knownVNodes = new WeakSet<VNode>()
|
|
||||||
|
|
||||||
export function isVNode(value: any): boolean {
|
export function isVNode(value: any): boolean {
|
||||||
return knownVNodes.has(value)
|
return value && value._isVNode
|
||||||
}
|
}
|
||||||
|
|
||||||
export function createVNode(
|
export function createVNode(
|
||||||
@ -172,6 +171,7 @@ export function createVNode(
|
|||||||
: 0
|
: 0
|
||||||
|
|
||||||
const vnode: VNode = {
|
const vnode: VNode = {
|
||||||
|
_isVNode: true,
|
||||||
type,
|
type,
|
||||||
props,
|
props,
|
||||||
key: (props && props.key) || null,
|
key: (props && props.key) || null,
|
||||||
@ -204,10 +204,6 @@ export function createVNode(
|
|||||||
trackDynamicNode(vnode)
|
trackDynamicNode(vnode)
|
||||||
}
|
}
|
||||||
|
|
||||||
if (__DEV__) {
|
|
||||||
knownVNodes.add(vnode)
|
|
||||||
}
|
|
||||||
|
|
||||||
return vnode
|
return vnode
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -220,6 +216,7 @@ function trackDynamicNode(vnode: VNode) {
|
|||||||
|
|
||||||
export function cloneVNode(vnode: VNode): VNode {
|
export function cloneVNode(vnode: VNode): VNode {
|
||||||
return {
|
return {
|
||||||
|
_isVNode: true,
|
||||||
type: vnode.type,
|
type: vnode.type,
|
||||||
props: vnode.props,
|
props: vnode.props,
|
||||||
key: vnode.key,
|
key: vnode.key,
|
||||||
|
Loading…
Reference in New Issue
Block a user