perf: optimize public properties access on componentProxy
This commit is contained in:
parent
c73d889235
commit
d6da48a33f
@ -94,29 +94,31 @@ export const PublicInstanceProxyHandlers: ProxyHandler<any> = {
|
|||||||
// is the multiple hasOwn() calls. It's much faster to do a simple property
|
// is the multiple hasOwn() calls. It's much faster to do a simple property
|
||||||
// access on a plain object, so we use an accessCache object (with null
|
// access on a plain object, so we use an accessCache object (with null
|
||||||
// prototype) to memoize what access type a key corresponds to.
|
// prototype) to memoize what access type a key corresponds to.
|
||||||
const n = accessCache![key]
|
if (key[0] !== '$') {
|
||||||
if (n !== undefined) {
|
const n = accessCache![key]
|
||||||
switch (n) {
|
if (n !== undefined) {
|
||||||
case AccessTypes.DATA:
|
switch (n) {
|
||||||
return data[key]
|
case AccessTypes.DATA:
|
||||||
case AccessTypes.CONTEXT:
|
return data[key]
|
||||||
return renderContext[key]
|
case AccessTypes.CONTEXT:
|
||||||
case AccessTypes.PROPS:
|
return renderContext[key]
|
||||||
return propsProxy![key]
|
case AccessTypes.PROPS:
|
||||||
|
return propsProxy![key]
|
||||||
|
}
|
||||||
|
} else if (data !== EMPTY_OBJ && hasOwn(data, key)) {
|
||||||
|
accessCache![key] = AccessTypes.DATA
|
||||||
|
return data[key]
|
||||||
|
} else if (hasOwn(renderContext, key)) {
|
||||||
|
accessCache![key] = AccessTypes.CONTEXT
|
||||||
|
return renderContext[key]
|
||||||
|
} else if (hasOwn(props, key)) {
|
||||||
|
// only cache props access if component has declared (thus stable) props
|
||||||
|
if (type.props != null) {
|
||||||
|
accessCache![key] = AccessTypes.PROPS
|
||||||
|
}
|
||||||
|
// return the value from propsProxy for ref unwrapping and readonly
|
||||||
|
return propsProxy![key]
|
||||||
}
|
}
|
||||||
} else if (data !== EMPTY_OBJ && hasOwn(data, key)) {
|
|
||||||
accessCache![key] = AccessTypes.DATA
|
|
||||||
return data[key]
|
|
||||||
} else if (hasOwn(renderContext, key)) {
|
|
||||||
accessCache![key] = AccessTypes.CONTEXT
|
|
||||||
return renderContext[key]
|
|
||||||
} else if (hasOwn(props, key)) {
|
|
||||||
// only cache props access if component has declared (thus stable) props
|
|
||||||
if (type.props != null) {
|
|
||||||
accessCache![key] = AccessTypes.PROPS
|
|
||||||
}
|
|
||||||
// return the value from propsProxy for ref unwrapping and readonly
|
|
||||||
return propsProxy![key]
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// public $xxx properties & user-attached properties (sink)
|
// public $xxx properties & user-attached properties (sink)
|
||||||
|
Loading…
Reference in New Issue
Block a user