perf(ivy): avoid duplicate state lookup and default function parameters (#34183)
Includes a few minor performance improvements: * In the `nextContext` instruction we assign a new LView to the `LFrame.contextLView` and then we immediately look it up to get its context. We don't need to do that since we know the view that was assigned already. * Removes the default value for the `level` parameter of `nextContextImpl` because it generates more code in es5 and is internal-only. * Removes the default parameter from `setActiveHostElement` since it generates extra code and it's an internal function. * Makes a check in `setElementExitFn` more strict since we're guaranteed for the value to match the type. PR Close #34183
This commit is contained in:
parent
fcbc38cb22
commit
a295255e58
|
@ -302,7 +302,7 @@ function setActiveElementFlag(flag: ActiveElementFlags) {
|
||||||
* @param elementIndex the element index value for the host element where
|
* @param elementIndex the element index value for the host element where
|
||||||
* the directive/component instance lives
|
* the directive/component instance lives
|
||||||
*/
|
*/
|
||||||
export function setActiveHostElement(elementIndex: number | null = null) {
|
export function setActiveHostElement(elementIndex: number | null) {
|
||||||
if (hasActiveElementFlag(ActiveElementFlags.RunExitFn)) {
|
if (hasActiveElementFlag(ActiveElementFlags.RunExitFn)) {
|
||||||
executeElementExitFn();
|
executeElementExitFn();
|
||||||
}
|
}
|
||||||
|
@ -330,7 +330,7 @@ export function executeElementExitFn() {
|
||||||
*/
|
*/
|
||||||
export function setElementExitFn(fn: () => void): void {
|
export function setElementExitFn(fn: () => void): void {
|
||||||
setActiveElementFlag(ActiveElementFlags.RunExitFn);
|
setActiveElementFlag(ActiveElementFlags.RunExitFn);
|
||||||
if (instructionState.elementExitFn == null) {
|
if (instructionState.elementExitFn === null) {
|
||||||
instructionState.elementExitFn = fn;
|
instructionState.elementExitFn = fn;
|
||||||
}
|
}
|
||||||
ngDevMode &&
|
ngDevMode &&
|
||||||
|
@ -592,9 +592,10 @@ export function leaveView() {
|
||||||
instructionState.lFrame = instructionState.lFrame.parent;
|
instructionState.lFrame = instructionState.lFrame.parent;
|
||||||
}
|
}
|
||||||
|
|
||||||
export function nextContextImpl<T = any>(level: number = 1): T {
|
export function nextContextImpl<T = any>(level: number): T {
|
||||||
instructionState.lFrame.contextLView = walkUpViews(level, instructionState.lFrame.contextLView !);
|
const contextLView = instructionState.lFrame.contextLView =
|
||||||
return instructionState.lFrame.contextLView[CONTEXT] as T;
|
walkUpViews(level, instructionState.lFrame.contextLView !);
|
||||||
|
return contextLView[CONTEXT] as T;
|
||||||
}
|
}
|
||||||
|
|
||||||
function walkUpViews(nestingLevel: number, currentView: LView): LView {
|
function walkUpViews(nestingLevel: number, currentView: LView): LView {
|
||||||
|
|
Loading…
Reference in New Issue