From 561ec6a5be1f795ff29b511bf87f566964519999 Mon Sep 17 00:00:00 2001 From: Pawel Kozlowski Date: Fri, 26 Jul 2019 11:52:15 +0200 Subject: [PATCH] perf(ivy): stricter null checks (#31839) PR Close #31839 --- packages/core/src/render3/hooks.ts | 23 +++++++++++-------- .../core/src/render3/instructions/shared.ts | 2 +- packages/core/src/render3/state.ts | 4 ++-- 3 files changed, 17 insertions(+), 12 deletions(-) diff --git a/packages/core/src/render3/hooks.ts b/packages/core/src/render3/hooks.ts index 3d87e04401..35678c7d68 100644 --- a/packages/core/src/render3/hooks.ts +++ b/packages/core/src/render3/hooks.ts @@ -185,18 +185,23 @@ export function executeHooks( checkNoChangesMode: boolean, initPhaseState: InitPhaseState, currentNodeIndex: number | null | undefined): void { if (checkNoChangesMode) return; - const hooksToCall = (currentView[FLAGS] & LViewFlags.InitPhaseStateMask) === initPhaseState ? - firstPassHooks : - checkHooks; - if (hooksToCall) { - callHooks(currentView, hooksToCall, initPhaseState, currentNodeIndex); + + if (checkHooks !== null || firstPassHooks !== null) { + const hooksToCall = (currentView[FLAGS] & LViewFlags.InitPhaseStateMask) === initPhaseState ? + firstPassHooks : + checkHooks; + if (hooksToCall !== null) { + callHooks(currentView, hooksToCall, initPhaseState, currentNodeIndex); + } } + // The init phase state must be always checked here as it may have been recursively updated - if (currentNodeIndex == null && - (currentView[FLAGS] & LViewFlags.InitPhaseStateMask) === initPhaseState && + let flags = currentView[FLAGS]; + if (currentNodeIndex == null && (flags & LViewFlags.InitPhaseStateMask) === initPhaseState && initPhaseState !== InitPhaseState.InitPhaseCompleted) { - currentView[FLAGS] &= LViewFlags.IndexWithinInitPhaseReset; - currentView[FLAGS] += LViewFlags.InitPhaseStateIncrementer; + flags &= LViewFlags.IndexWithinInitPhaseReset; + flags += LViewFlags.InitPhaseStateIncrementer; + currentView[FLAGS] = flags; } } diff --git a/packages/core/src/render3/instructions/shared.ts b/packages/core/src/render3/instructions/shared.ts index cae83517f6..614c9f62ab 100644 --- a/packages/core/src/render3/instructions/shared.ts +++ b/packages/core/src/render3/instructions/shared.ts @@ -120,7 +120,7 @@ export function refreshDescendantViews(lView: LView) { export function setHostBindings(tView: TView, viewData: LView): void { const selectedIndex = getSelectedIndex(); try { - if (tView.expandoInstructions) { + if (tView.expandoInstructions !== null) { let bindingRootIndex = viewData[BINDING_INDEX] = tView.expandoStartIndex; setBindingRoot(bindingRootIndex); let currentDirectiveIndex = -1; diff --git a/packages/core/src/render3/state.ts b/packages/core/src/render3/state.ts index a62e169d08..a162ae1edb 100644 --- a/packages/core/src/render3/state.ts +++ b/packages/core/src/render3/state.ts @@ -167,8 +167,8 @@ let activeDirectiveSuperClassHeight = 0; */ export function setActiveHostElement(elementIndex: number | null = null) { if (_selectedIndex !== elementIndex) { - setSelectedIndex(elementIndex == null ? -1 : elementIndex); - activeDirectiveId = elementIndex == null ? 0 : MIN_DIRECTIVE_ID; + setSelectedIndex(elementIndex === null ? -1 : elementIndex); + activeDirectiveId = elementIndex === null ? 0 : MIN_DIRECTIVE_ID; activeDirectiveSuperClassDepthPosition = 0; activeDirectiveSuperClassHeight = 0; }